Proxies events from Sendgrid and SocketLabs to FxA SQS queues.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
tests
.eslintrc.json
.gitignore
.travis.yml
LICENSE
README.md
index.js
package-lock.json
package.json
sendgrid.js
socketlabs.js

README.md

fxa-email-event-proxy

Build Status CircleCI

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

Tagging releases

git tag -a v1.$TRAIN.$PATCH
git push origin v1.$TRAIN.$PATCH

This will kick off a build in CircleCI.

Setting up Lambda

  1. Run npm run build to create a zip archive, or use a pre-built artifact from the tag build in CI.

  2. Create a new Lambda function. Upload the zip.

  3. Assign it roles to access CloudWatch Logs and SQS bounce, complaint and delivery queues..

  4. 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 sendgrid and socketlabs.

    • 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 and SQS_REGION if necessary.

  5. 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

  6. 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:

Screenshot showing AWS Lambda config to set up fxa-email-event-proxy for Sendgrid

You can see working example Lambda functions in the dev IAM: