This repo proxies events
from the Sengrid Event Webhook
and the SocketLabs Notification API
to our SES bounce, complaint and delivery queues.
In doing so,
it acts as a bridge
that enables our existing queue-processing logic
to handle notifications that originate from Sendgrid and SocketLabs.
It runs in AWS Lambda,
behind an API Gateway trigger.
Note that events from only one of either Sendgrid or SocketLabs can be processed by any single instance of this code. If you want to process both, you'll need to configure two separate instances.
The code runs in node.js version 8 or later. Assuming that you have node and npm set up already, you can install the dependencies locally like so:
You can run the tests like so:
You can manually build a zip bundle for Lambda like so:
npm run build
git tag -a v1.$TRAIN.$PATCH git push origin v1.$TRAIN.$PATCH
This will kick off a build in CircleCI.
Setting up Lambda
npm run buildto create a zip archive, or use a pre-built artifact from the tag build in CI.
Create a new Lambda function. Upload the zip.
Assign it roles to access CloudWatch Logs and SQS bounce, complaint and delivery queues..
Set environment variables:
AUTH: Random authentication string used to block requests. By including the same string in your requests from Sendgrid/SocketLabs as the value of an
?auth=query parameter, you can ensure that only valid traffic is able to send events successfully.
PROVIDER: Name of the provider this instance will handle requests from. Valid values are
BOUNCE_QUEUE_URL: URL of the bounce SQS queue
COMPLAINT_QUEUE_URL: URL of the complaint SQS queue
DELIVERY_QUEUE_URL: URL of the delivery SQS queue
You can also set explicit values for
If it's for SocketLabs, also set these environment variables based on settings available in the SocketLabs control panel:
Create an API Gateway trigger. Then configure Sendgrid or SocketLabs to use that URL for the webhook.
Config should look something like this at the end:
You can see working example Lambda functions in the dev IAM: