Skip to content

Commit

Permalink
Add SNS topic, SES config set for delivery events
Browse files Browse the repository at this point in the history
This is in preparation for having the Lambda function handle SES
delivery event notifications for bounces, complaints, etc.

I recently realized that it's up to the EListMan application to manage
this, since we're not using AWS SES list management. Once I successfully
deploy the infrastructure, I'll turn to handling the events. Hopefully
it won't take as much time and effort as handling HTTP API and mailto
events.
  • Loading branch information
mbland committed Apr 10, 2023
1 parent 258f612 commit b2722a4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ This software is made available as [Open Source software][oss-def] under the
- [Setting up event notification for Amazon SES][]
- [Receiving Amazon SES notifications using Amazon SNS][]
- [Contents of event data that Amazon SES publishes to Amazon SNS][]
- [How email sending works in Amazon SES][]

[Go]: https://go.dev/
[Amazon Web Services]: https://aws.amazon.com
Expand Down Expand Up @@ -388,3 +389,4 @@ This software is made available as [Open Source software][oss-def] under the
[Setting up event notification for Amazon SES]: https://docs.aws.amazon.com/ses/latest/dg/monitor-sending-activity-using-notifications.html
[Receiving Amazon SES notifications using Amazon SNS]: https://docs.aws.amazon.com/ses/latest/dg/monitor-sending-activity-using-notifications-sns.html
[Contents of event data that Amazon SES publishes to Amazon SNS]: https://docs.aws.amazon.com/ses/latest/dg/event-publishing-retrieving-sns-contents.html
[How email sending works in Amazon SES]: https://docs.aws.amazon.com/ses/latest/dg/send-email-concepts-process.html
44 changes: 43 additions & 1 deletion template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Resources:
ApiId: !Ref HttpApi
Path: /unsubscribe/{email}/{uid}
Method: POST
DeliveryNotification:
Type: SNS
Properties:
Topic: !Ref DeliveryNotificationsTopic

ApiMapping:
Type: AWS::ApiGatewayV2::ApiMapping
Expand All @@ -112,7 +116,8 @@ Resources:
Properties:
AccessLogSettings:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-stage-accesslogsettings.html
# https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging.html?icmpid=apigateway_console_help
# https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging.html
# https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging-variables.html
DestinationArn: !GetAtt ApiAccessLogs.Arn
Format: '"$context.identity.sourceIp - - [$context.requestTime] "$context.httpMethod $context.path $context.protocol" $context.status $context.responseLength $context.requestId"'
DefaultRouteSettings:
Expand Down Expand Up @@ -157,6 +162,43 @@ Resources:
FunctionArn: !GetAtt Function.Arn
DependsOn: ReceiptRuleSetPermission

DeliveryNotificationsTopic:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-topic.html
Type: AWS::SNS::Topic
Properties:
TopicName: !Sub "${AWS::StackName}"

SendingConfigurationSet:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ses-configurationset.html
Type: AWS::SES::ConfigurationSet
Properties:
Name: !Sub "${AWS::StackName}"
DeliveryOptions:
TlsPolicy: REQUIRE
SendingOptions:
SendingEnabled: true
SuppressionOptions:
SuppressedReasons:
- COMPLAINT
- BOUNCE

SendingConfigurationSetDestination:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ses-configurationseteventdestination.html
Type: AWS::SES::ConfigurationSetEventDestination
Properties:
ConfigurationSetName: !Ref SendingConfigurationSet
EventDestination:
Name: "SNS"
Enabled: true
MatchingEventTypes:
- send
- delivery
- reject
- bounce
- complaint
SnsDestination:
TopicARN: !Ref DeliveryNotificationsTopic

Outputs:
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
Api:
Expand Down

0 comments on commit b2722a4

Please sign in to comment.