Skip to content

Instantly share code, notes, and snippets.

@joawan
Created August 25, 2021 13:33
Show Gist options
  • Save joawan/e9e42c98b1cb106294a2b5ba04b8f540 to your computer and use it in GitHub Desktop.
Save joawan/e9e42c98b1cb106294a2b5ba04b8f540 to your computer and use it in GitHub Desktop.
AWS SAM for SQS to Lambda to SES
SendLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/send-mail/
Description: Polls SQS, builds email, sends to SES
MemorySize: 256
Policies:
- SQSPollerPolicy:
QueueName: !GetAtt ApiQueue.QueueName
- SESCrudPolicy:
IdentityName: !Ref SenderIdentity
Events:
SQSEvent:
Type: SQS
Properties:
BatchSize: 1
Queue: !GetAtt ApiQueue.Arn
DeadLetterQueue:
Type: SQS
TargetArn: !GetAtt ApiQueueDLQ.Arn
Environment:
Variables:
SENDER_EMAIL: !Ref Sender
SES_CONFIG_SET: !Ref SESConfigSet
# Creating Event destination configuration set
SESConfigSet:
Type: AWS::SES::ConfigurationSet
Properties:
Name: sam-pigeon-event-config
# Lambda function that runs on deploy to configure SES Event Destination
SetupSESLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/setup-ses-config/
Description: Custom resources to configure SES
Timeout: 30
Policies:
- Statement:
- Sid: AllowSesConfigEventCrud
Effect: Allow
Action:
- ses:CreateConfigurationSetEventDestination
- ses:UpdateConfigurationSetEventDestination
- ses:DeleteConfigurationSetEventDestination
Resource: "*"
# Config to run the Lambda function above
CustomSESConfigEventDestination:
Type: Custom::SESConfigurationEventDestination
Properties:
ServiceToken: !GetAtt SetupSESLambda.Arn
ConfigSetEventDestinationName: sam-pigeon-event-sns-config
ConfigSetName: !Ref SESConfigSet
SNSTopicArn: !Ref EventsSNS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment