Skip to content

crocoder-dev/serverless-email-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Serverless Email

How to use Amazon SES with AWS lambdas
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

Product Name Screen Shot

This is a project for educational purposes.

  • How to deploy & enable different AWS services with Serverless
  • How to use Amazon EventBridge for communication between multiple AWS Lambda Applications
  • How to use DynamoDB Streams to trigger AWS Lambda Functions
  • How to trace the requests through this Serverless Email solution with AWS X-Ray

(back to top)

Built With

(back to top)

Getting Started

Prerequisites

  1. You need to have installed Node.js on your local machine.
  2. You need to have installed Serverless on your local machine.
    npm install -g serverless
  3. You need to have an AWS account available.
  4. Log in in the AWS & create an access key for CLI access.
  5. Configure your Serverless credentials.
    serverless config credentials --provider provider --key key --secret secret
  6. Provision an Amazon EventBridge Bus.
  7. Setup a new email in Amazon Simple Email Service.

Installation

  1. Clone the repo
    git clone https://github.com/crocoder-dev/serverless-email-example.git
  2. Install NPM packages in serverless-api, serverless-mail & serverless-reports folders
    cd serverless-api & npm install & cd..
    cd serverless-mail & npm install & cd..
    cd serverless-reports & npm install & cd..
  3. Create .env files in serverless-api, serverless-mail & serverless-reports folders
    cd serverless-api & touch .env & cd..
    cd serverless-mail & touch .env & cd..
    cd serverless-reports & touch .env & cd..
  4. Update .env file in serverless-api folder with these variables. USERS_TABLE & POINTS_TABLE will be the names of DynamoDB Tables created when serverless-api is deployed. AUTH_TOKEN is the value that should be put in Authorization header field to use the deployed API. EVENT_BUS_ARN is the ARN of the previously created EventBridge Bus.
    USERS_TABLE=*table-name*
    POINTS_TABLE=*table-name*
    EVENT_BUS_ARN=*event-bus-arn*
    AUTH_TOKEN=*auth-token*
  5. Update .env file in serverless-mail folder with these variables. SES_ARN is the ARN of the previously setup Amazon Simple Email Service and EMAIL is the email address of the EMAIL EVENT_BUS_ARN is the ARN of the previously created EventBridge Bus.
    SES_ARN=*sas-arn*
    EMAIL=*email-address*
    EVENT_BUS_ARN=*event-bus-arn*
  6. Update .env file in serverless-reports folder with these variables. DATA_TABLE will be the name of DynamoDB Table created when serverless-reports is deployed. EVENT_BUS_ARN is the ARN of the previously created EventBridge Bus.
    DATA_TABLE=*table-name*
    EVENT_BUS_ARN=*event-bus-arn*

(back to top)

Usage

serverless-api

serverless-api project deploys an instance of Amazon API Gateway. Every endpoint call is authorized by authorizer lambda function. You need to add header Authorization to every request with the same value as AUTH_TOKEN env variable you specified in serverless-api/.env file.

It provisions two endpoint /points & /users. /points endpoint supports POST requests with the body schema specified here and calls AWS Lambda with this code. /users endpoint supports POST & DELETE requests with the body schema specified here: POST & DELETE and calls AWS Lambdas with code located here: POST & DELETE.

When new point or user is created and stored (or deleted) in DynamoDB tables, the changes are streamed to the notifyUser or transformPoints AWS Lambda functions. Both functions send events to the EventBridge bus instance.

serverless-mail

serverless-mail project deploys only one AWS Lambda function that runs this code. This AWS Lambda functions triggers when there is an event with detail-type: email.send sent to EventBridge bus instance. The schema of the event can be found here.

serverless-reports

serverless-reports project deploys two AWS Lambda functions: saveData & sendReports.

saveData is triggered when there is an event with detail-type: point.created sent to EventBridge bus instance. The schema of the event can be found here.

sendReports is triggered when there is an event with detail-type: report.send sent to EventBridge bus instance. The schema of the event can be found here.

AWS X-Ray

AWS X-Ray tracing is enabled for every lambda and managed services that can be deployed by serverless-reports, serverless-mail & serverless-api. You can see traces and service maps of the whole solution by visiting this link.

X-Ray Service Map example

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

David Abram - @devabram - [email protected]

Project Link: https://github.com/crocoder-dev/serverless-email-example

(back to top)

Acknowledgments

(back to top)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published