AWS API gateway + AWS Lambda + NodeJS REST API development


API Gateway is gateway service of AWS cloud platform to access backed services like EC2 and Lambda as HTTP endpoints. 
API gateway provides

— Security 
 — Monitoring 
 — Deployment Life Cycle 
 — Custom Request and Response 
 — Request Validation

features to maintain and monitor apis.

AWS Lambda is serverless service of AWS cloud platform to develop serverless solutions with

  • Scalability
  • Security
  • Monitoring
  • Version management

Lambda support following programming languages.

  • Python
  • Javascript
  • Java
  • GoLang
  • C#
  • Powershell

Pre-requisite — An AWS account —

Create a Lambda function ⚡️ ⚡️

STEP 1 — Goto — Lambda home —

STEP 2 — Click on create function

STEP 3 — Select Author from scratch and fill the given form.

Name — myLambda

Runtime — Node.JS8.10

Role — Create new role from one or more templates

Role Name — myLambdaRole

Policy Template — Amazon S3 object read only permission

Click to “Create function” button.

Congratulations your lambda function got created 👏 👏

myLambda function created

Create an API 🔌

STEP 1 — Goto — API Gateway home —


STEP 2 — Click CreateAPI button and insert required details

New API creation

Api name — myLambdaAPI

Description — A basic api creation

Endpoint Type — Regional

and click “CreateAPI” button.

Congratulations your new AWS api got created 👏 👏

API dashboard —

myLambda API created

API and Lambda Function Linking 🔗 🔗

STEP 1 — Click on api(myLambdaApi) => click on action drop down => Click Create Method

STEP 2 — select ANY from drop down and click ☑️ button.

Create Method

STEP 3 — Select Radio button “Lambda Function” and enter lambda function name “myLambda” and click save button

STEP 4 — click OK to confirm Lambda service execution permission to API gateway.

STEP 5 — Click on Test Icon ⚡️

AWS Gateway Method setup

STEP 6 — select GET method from dropdown and click Test button.

AWS api gateway test screen

Expected output

"statusCode": 200,
"body": "\"Hello from Lambda!\""
AWS lambda testing screen.

Congratulations AWS api gateway and Lambda function linking done successfully. 👏 👏

Deploy AWS Gateway API 🚀 🚀 🚀

STEP 1 — Goto API dashboard — API dashboard — and click myLambdaAPI

api dashboard

STEP 2 — Click Actions drop down => click Deploy API

Opened Action Dropdown

STEP 3 — select [new State]

select new stage

Enter stage details and click Deploy button.

STEP 4 — Goto to stages and click “Invoke URL

Expected output

lambda api response

Congratulations you public api is ready 🔥 🔥