This is a simple HTTP Server to Handle API requests from Amazon SNS for SES Email Bounces. It exposes an api endpoint for receiving HTTP requests from SNS, and stores the bounce details in a CSV file. This CSV file is emailed every night to specified email addresses, and it can also be accessed via an API end point.
## API EndpointsEndpoint | Method | Description |
---|---|---|
/sns |
POST | Called by Amazon SNS to post the Subscribe and Bounce events |
/download |
GET | Downlod the last 30 days of Bounce data in CSV format |
npm install -g yarn
npm install
Make sure you update the file ".env" with your SMTP server details and recipient email address.
To run your script on a Linux server so it keeps running after you close the terminal, follow these steps:nohup
allows the process to continue running in the background even after the terminal is closed.
Run the script as follows:
nohup node path/to/your/script.js > output.log 2> error.log &
output.log
: Captures the standard output of your script.error.log
: Captures the standard error (errors and logs sent viaconsole.error
).&
: Runs the process in the background.
You can monitor the logs at any time:
- Standard output:
tail -f output.log
- Errors:
tail -f error.log
To stop the script, find its process ID (PID) using:
ps aux | grep node
Then kill the process:
kill <PID>
Using a process manager like PM2 or systemd provides better management for scripts. PM2 is particularly user-friendly for Node.js applications:
npm install -g pm2
pm2 start path/to/your/script.js --name sns-ses-handler
pm2 logs sns-ses-handler
Enable PM2 to start the script automatically on server boot:
pm2 startup
pm2 save
This approach ensures reliability and ease of monitoring. Let me know if you want detailed steps for setting up PM2 or using another method.
- In the Amazon SNS edit your subscription, and expand the "Delivery Policy HTTP/S - Optional" Section.
- Uncheck "Use Default Delivery Policy"
- Change Content Type to : application/json
- Save