This example demonstrates how to deploy a NodeJS function running on AWS Lambda using the traditional Serverless Framework. The deployed function works with multiple type of event definitions.
This Example works with both cron events and httpApi events.
When deployed the AWS Lambda function sends Emails by using AWS Simple Email Service(SES). Now the Emails can be sent either by an AWS HTTP API event or by a cron like fashion to a stipulated time interval set in the AWS Cloudformation Stack.
All logs for the function is kept in AWS Cloudwatch i.e persistent. AWS EventBridge is used to handle both types of schedule and http events.
To use the code in this example you must have an valid AWS account and necessary AWS IAM roles and programmatic access to an user.
- AWS Lambda function using NodeJS
- Function is using latest version of AWS SDK JavaScript v3 with all ES6+ syntaxes like Promises,
async/await
- Function are deployed using Serverless Framework.
-
serverless.jsonis used for deployment configuration instead ofserverless.yml. - All the deployment is created in AWS S3 to store the
.zipof the function code and AWS CloudFormation Stack.
- Two types of events are supported
httpAPiandschedule - AWS HTTP API are using AWS API GateWay
- All Emails are sent using AWS Simple Email Service(SES). For that purpose valid Identities must be created.
- Email Templates are created using HTML5 and CSS3
- This APIs can also be consumed by any Frontend Application.
- NPM dependencies are used for various purposes.
- Custom Headers are added with the response for obvious security reasons.
First clone the repo
$ git clone git@github.com:anijitsahu/simple-aws-lambda-mongodb.gitInstall all the necessary dependencies by going inside the directory
$ cd simple-aws-lambda-mongodb $ npm installIn order to deploy the example, you need to run the following command:
$ serverless deploy After successful deployment, you can invoke the deployed function. All the cron events will invoke the deployed functions in stipulated time interval.
However, to call using httpApi you can use any REST Client like Talend API Tester with the url and HTTP Verbs as shown in Terminal after using serverless deploy.