2.9 KiB
fxa-email-event-proxy
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
in fxa-email-service
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.
Dev environment
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:
npm i
You can run the tests like so:
npm t
You can manually build a zip bundle for Lambda like so:
npm run build
Setting up Lambda
-
Run
npm run build
to 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 aresendgrid
andsocketlabs
. -
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
SQS_ACCESS_KEY
,SQS_SECRET_KEY
andSQS_REGION
if necessary. -
-
If it's for SocketLabs, also set these environment variables based on settings available in the SocketLabs control panel:
-
SOCKETLABS_SECRET_KEY
-
SOCKETLABS_VALIDATION_KEY
-
-
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: