Monitoring Your Email Bounces and Bounce Rate using Amazon SES, Lambda, SNS, and DynamoDB
Learn how to build a robust email bounce monitoring system using AWS services to maintain a healthy SES reputation and prevent service disruptions.
Monitoring Your Email Bounces and Bounce Rate using Amazon SES, Lambda, SNS, and DynamoDB
When using Amazon SES, a situation may occur where your Account status in the Amazon SES Reputation Dashboard changes from HEALTHY, causing Amazon to stop the ability to send emails. To prevent this, it is better to start monitoring your Reputation right after going into production.
The Solution Stack
An adequate bundle of services for this includes:
- AWS Lambda: Process bounce notifications
- Amazon SNS: Receive events from Amazon SES
- Amazon DynamoDB: Store bounce data for analysis
Amazon SNS will get events from Amazon SES and trigger Lambda. The Lambda function will store data to DynamoDB and do other things that you want — for example, remove an email address from a subscription list via an API, or send a message to Slack/Telegram/Messenger.
Setting Up SNS Topics
First, in the Notifications settings of your domain, add Amazon SNS Topics for the Bounces, Complaints and Deliveries events.
You can use 1 topic for all events, separating is optional. For example, if you want to send Complaint events to Lambda and the email of the administrator, it is better to separate.
Creating the Lambda Function
Create a Lambda function named ses-notification-nodejs:
- Use Node.js 12.x Runtime with default settings
- This is enough for this task
Setting Up DynamoDB
Create a DynamoDB table:
- Table name:
mailing - Primary key:
UserId - Default settings will be enough for a start
- You can fine-tune it later
IAM Permissions
Go to IAM and add a permission to the Lambda role. The best option is to add the permission to exactly one table. This follows the principle of least privilege and ensures your Lambda function only has access to the resources it needs.
Lambda Function Code
The Lambda function processes SNS notifications from SES and stores them to DynamoDB. Key features:
- Parse incoming SNS messages
- Extract bounce/complaint information
- Store data in DynamoDB for tracking
- Optional: Send notifications to external services (Slack, Telegram, etc.)
Benefits
With this setup, you can:
- Monitor all Bounce and Complaint events from your SES service
- Keep your Amazon SES in a healthy state
- Prevent service disruptions due to reputation issues
- Build automated responses to email issues
Code Repository
You can find examples with Telegram notification in my repository: zagran/ses-notification-nodejs
This monitoring system is essential for any production application using Amazon SES to ensure reliable email delivery and maintain sender reputation.