-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix notifications access from service (#835)
Fix ability for ECS service to access Pinpoint: - Add VPC endpoints for Pinpoint services - Add IAM policy for accessing Pinpoint and SES to service Also add notifications test endpoint to example app for testing: - Add /notifications page where you can enter an email address and get a test notification to that email address - Add links to the homepage to all the test pages in the example app
- Loading branch information
Showing
9 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
resource "aws_iam_policy" "access" { | ||
name = "${var.name}-notifications-access" | ||
description = "Policy for calling SendMessages and SendUsersMessages on Pinpoint app ${var.name}" | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
# From https://docs.aws.amazon.com/pinpoint/latest/developerguide/permissions-actions.html#permissions-actions-apiactions-messages | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"mobiletargeting:SendMessages", | ||
"mobiletargeting:SendUsersMessages" | ||
] | ||
Resource = "${aws_pinpoint_app.app.arn}/messages" | ||
}, | ||
|
||
# From https://docs.aws.amazon.com/pinpoint/latest/developerguide/permissions-ses.html | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"ses:SendEmail", | ||
"ses:SendRawEmail", | ||
] | ||
Resource = [ | ||
var.domain_identity_arn, | ||
"arn:*:ses:*:*:configuration-set/*", | ||
] | ||
} | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
output "app_id" { | ||
value = aws_pinpoint_app.app.application_id | ||
} | ||
|
||
output "access_policy_arn" { | ||
value = aws_iam_policy.access.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import boto3 | ||
|
||
def send_email(to: str, subject: str, message: str): | ||
pinpoint_client = boto3.client("pinpoint") | ||
app_id = os.environ["AWS_PINPOINT_APP_ID"] | ||
|
||
response = pinpoint_client.send_messages( | ||
ApplicationId=app_id, | ||
MessageRequest={ | ||
"Addresses": { | ||
to: { | ||
"ChannelType": "EMAIL" | ||
} | ||
}, | ||
"MessageConfiguration": { | ||
"EmailMessage": { | ||
"SimpleEmail": { | ||
"Subject": { | ||
"Charset": "UTF-8", | ||
"Data": subject | ||
}, | ||
"HtmlPart": { | ||
"Charset": "UTF-8", | ||
"Data": message | ||
}, | ||
"TextPart": { | ||
"Charset": "UTF-8", | ||
"Data": message | ||
} | ||
} | ||
} | ||
} | ||
} | ||
) | ||
print(response) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters