Skip to content

Process SendGrid events using AWS Lambda and store them in MongoDB

Notifications You must be signed in to change notification settings

memiah/sendgrid-eventkit-lambda-mongodb

Repository files navigation

sendgrid-eventkit-lambda-mongodb - Build Status

Table of Contents

Motivation

Provision a Lambda based relay script that will, self test, self deploy and consume SendGrid webhook endpoints and relay them to Mongodb's Atlas cloud service. Also included as part of the microservice is information on how to setup the AWS IAM policies with the least permissive policy possible. The service is deployable using the Travis github hooks and will automatically test with local integrations of NodeJS and MongoDB that are stored within the docker containers.

Local Development via Docker with Mapped volumes

The folder ./.docker folder contains the dev containers as well as the travis production containers. .env.example must be populated when running in development as per the process below.

Local Dependancies

  1. Docker
  2. docker-compose
  3. npm

Process

  1. Copy .env.example to .env
  2. Update ENVIRONMENT to "development"
  3. Change TESTFILE location if desired
  4. Install NPM dependancies
npm install
  1. Init Docker
# use docker to run test
docker-compose -f ./docker-compose.yml -f ./.docker/docker-compose.dev.yml up --exit-code-from app
# clean up containers
docker rm -v sendgrid-eventkit-lambda-mongodb-mongo 
  • This will run the lambda function with the 'event' argument data overwritten from the TESTFILE json.
  • docker exits when lambda function returns code (sendgrid_app_1 exited with code ~)
  • ~ = 0 = success;

Pending updates

  • enforce unique index on sg_message_id
  • handle unique key errors in insertMany
  • replace vagrant with docker for local development
  • add packaged staging with Docker
  • improve debug testdata files with unique event ids
  • add testing and travis CI
    • test deep nested lambda function handlers (Result: namespace/component.handler)
    • setup IAM user for Travis
    • document Travis:IAM process
    • set up travis build file using docker
    • add Lambda deployment to travis (https://docs.travis-ci.com/user/deployment/lambda/)
  • document AWS API Gateway setup

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

Process SendGrid events using AWS Lambda and store them in MongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •