How to use Amazon SES with AWS lambdas
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
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
- You need to have installed Node.js on your local machine.
- You need to have installed Serverless on your local machine.
npm install -g serverless
- You need to have an AWS account available.
- Log in in the AWS & create an access key for CLI access.
- Configure your Serverless credentials.
serverless config credentials --provider provider --key key --secret secret
- Provision an Amazon EventBridge Bus.
- Setup a new email in Amazon Simple Email Service.
- Clone the repo
git clone https://github.com/crocoder-dev/serverless-email-example.git
- 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..
- 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..
- 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 inAuthorization
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*
- Update .env file in serverless-mail folder with these variables.
SES_ARN
is the ARN of the previously setup Amazon Simple Email Service andEMAIL
is the email address of theEMAIL
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*
- 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*
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 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 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 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.
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
David Abram - @devabram - [email protected]
Project Link: https://github.com/crocoder-dev/serverless-email-example