anijitsao / simple-aws-sqs-lambda-microservices

Simple Microservices implementation using Node JS, AWS Lambda and AWS Simple Queue Service (SQS) along with AWS SDK for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simple-aws-sqs-lambda-microservices

Simple Microservices APIs implementation using Node JS with AWS Lambda Functions and AWS Simple Queue Service along with AWS Simple Email Service.

This example illustrates how to deploy Microservices using NodeJS functions running on AWS Lambda using the traditional Serverless Framework. Microservices talk with each other using message queue implemented through AWS Simple Queue Service.

This Example works with AWS HTTP API events i.e. httpApi as well as AWS Simple Queue Service events i.e. sqs. When deployed the functions can work with various types of AWS S3 operations like ListBuckets, CreateBucket, PutObject, GetObject.

All logs for the function is kept in AWS Cloudwatch i.e persistent.

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. You should also have an AWS Simple Email Service Identity for sending Emails.

Features

  1. AWS Lambda functions 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.yml is used for deployment configuration.
  3. All the deployment is created in AWS S3 to store the .zip of the function code and AWS CloudFormation Stack.
  4. Basic AWS S3 operations ListBuckets, CreateBucket, PutObject, GetObject are supported.

  1. AWS HTTP API are using AWS API GateWay
  2. Three types of events are supported namely httpApi, schedule and sqs.
  3. Emails are sent when the corresponing functions are invoked through HTTP POST request
  4. NPM dependencies are used for various purposes.
  5. This APIs can also be consumed by any Frontend Application.

Usage

First clone the repo

$ git clone https://github.com/anijitsao/simple-aws-sqs-lambda-microservices.git

Install all the necessary dependencies by going inside the directory

$ cd simple-aws-sqs-lambda-microservices

# To install necessary dependencies
$ npm install

Deployment

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

$ serverless deploy

# To deploy a particular function
$ serverless deploy function -f greeting

Invocation

After successful deployment, you can invoke the deployed functions.

However, to call HTTP API you can use any supported REST Client like Talend API Tester with the url and HTTP Verbs as shown in Terminal after using serverless deploy.

API Listing

API listing is given below, -

POST /url-of-the-deployed-lambda/sendmessage have the following input JSON

{
  "itemPurchased": [
    {
      "itemName":"Madhur Sugar",
      "qtyPurchased":"7"
    }
  ],
  "storeName": "Grofers"
}

GET /url-of-the-deployed-lambda/getcontents have no input JSON

POST /url-of-the-deployed-lambda/upload have the following input JSON

{
  "fileName": "hello.txt",
  "fileContents": "This is hello world text",
  "userId": "7840awuw4js568wm4nsuar5h" // optional
}

POST /url-of-the-deployed-lambda/greeting have the following input JSON

{
  "name": "John Doe",
}

About

Simple Microservices implementation using Node JS, AWS Lambda and AWS Simple Queue Service (SQS) along with AWS SDK for JavaScript


Languages

Language:JavaScript 92.9%Language:HTML 7.1%