Skip to content

anijitsao/simple-aws-lambda-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-aws-lambda-mongodb

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.

Features

  1. AWS Lambda function using NodeJS
  2. Function is using latest version of AWS SDK JavaScript v3 with all ES6+ syntaxes like Promises, async/await
  1. Function are deployed using Serverless Framework.
  2. serverless.json is used for deployment configuration instead of serverless.yml.
  3. All the deployment is created in AWS S3 to store the .zip of the function code and AWS CloudFormation Stack.
  1. Two types of events are supported httpAPi and schedule
  2. AWS HTTP API are using AWS API GateWay
  1. All Emails are sent using AWS Simple Email Service(SES). For that purpose valid Identities must be created.
  2. Email Templates are created using HTML5 and CSS3
  3. This APIs can also be consumed by any Frontend Application.
  1. NPM dependencies are used for various purposes.
  2. Custom Headers are added with the response for obvious security reasons.

Usage

First clone the repo

$ git clone git@github.com:anijitsahu/simple-aws-lambda-mongodb.git

Install all the necessary dependencies by going inside the directory

$ cd simple-aws-lambda-mongodb $ npm install

Deployment

In order to deploy the example, you need to run the following command:

$ serverless deploy 

Invocation

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.

Packages

No packages published