A lambda function that sends sns notifications about emails to elasticsearch
SES is capable of sending reports about email delivery (deliveries, bounces, rejects) to SNS. However, there's no built in way to pipe these reports into something like Elastic Search. This Lambda function bridges the gap and allows to send the reports to ES.
+-------+ +-------+ +--------+ +---------+
| SES +---> | SNS +---> | Lambda +---> | Elastic |
+-------+ +-------+ +--------+ +---------+
Lambda requires you to include any npm dependencies your function needs with the bundle. Prepare the zip bundle:
$ npm install --production
$ zip -r lambda-bundle.zip *
Then upload the bundle directly to Lambda through the upload button
There are couple of steps that need to be done on AWS console to make this work:
- Create a topic on SNS for the email deliveries.
- Set up notifications for you SES email address. Set these notifications to be sent to the topic you created.
- Create a lambda function with a trigger for SNS. Set the topic on that trigger to the topic you created.
- Subscribe to the topic and set Lambda as the destination for notifications.
The function expects several environment variables to be set:
BASE_URL
- The base url for ES instance.USER
- ES user.PASSWORD
- ES password.PREFIX
- The index name prefix. It will be appended with the current month. For example, ifPREFIX='aws-ses-emails'
the index name will beaws-ses-emails-2017-12-01
(for any day in December 2017).