-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix notifications access from service #154
Changes from all commits
e245464
887fa65
b9a7d7b
11da634
998c9a1
889b2af
7e1fa1a
01c988e
a9d73ff
f3efecf
807e8ee
3a4de91
2f46646
f6d6a07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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/*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason why this 2nd on isn't an arn as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. configuration sets don't actually have arns as far as i could tell. couldn't find it on AWS console, and don't see it in the outputs in the terraform aws_sesv2_configuration_set data source or resource, so you'd have to construct it manually. and in my opinion i don't think it's actually a big deal to allow the use of any configuration set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow... yeah no arns mentioned here. That's a new one for me! |
||
] | ||
} | ||
] | ||
}) | ||
} |
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called
mobile-targeting
in IAM but the VPC endpoints are["pinpoint", "email-smtp"]
??? bahThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i put mobiletargeting at first and got an error saying that doesn't exist.
also, the AWS docs don't mention "email-smtp" anywhere, instead they said to search for smtp and then click on that one, so I had to go to the console and search to find out that email-smtp was what they meant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amazing right?