SES Event Source


#1

I need to create an SES triggered function. It’s a typical SES design; a rule dumps the incoming email to S3 and then triggers a function. I know I can create the rule with CloudFormation but not sure how I’d define the event trigger in serverless.yml.


#2

This is a good question. I’m not sure you can use the baked in events.

However you could use the https://www.npmjs.com/package/serverless-plugin-existing-s3 plugin to listen to those s3 buckets where the emails are dumped.

Out of curiosity, what does the cloudformation for this look like?


#3

@DavidWells, thanks for the response.
Yesterday I was able to use the ‘AWS SES receive emails and process body’ example and add an SES rule in the Resources section (see below.) Only problem is that I can’t auto-create the S3 bucket Action because the S3 bucket doesn’t exist at the time the CloudFormation resources are created. So this gets me closest to an automated solution; I just have to go into the SES rule and add the S3 bucket action. When I remove the stack, I just have to first delete all content from the bucket and then Serverless removes it all. If I could create the bucket in the Resources section without screwing up the Event-based creation, I’d have a complete solution.

resources:
Resources:
S3EMailBucketPermissions:
Type: AWS::S3::BucketPolicy

ReceiptRule:
Type: AWS::SES::ReceiptRule
Properties:
RuleSetName: default-rule-set
Rule:
Name: {self:custom.sesRuleName} Enabled: true Recipients: - Fn::Join: ['', ["{self:custom.sesRuleName}", ‘@acme.com’] ]
ScanEnabled: true
Actions:
- StopAction:
Scope: RuleSet
# S3Action:
# BucketName: ${self:custom.bucketRef}