AWS API gateway + AWS Lambda + NodeJS REST API development

vinay mavi
Nov 5, 2018 · 4 min read
from— pexels.com

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 — https://portal.aws.amazon.com/billing/signup#/start

Create a Lambda function ⚡️ ⚡️

STEP 1 — Goto — Lambda home — https://us-east-2.console.aws.amazon.com/lambda/home?region=us-east-2#/functions

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 — https://us-east-2.console.aws.amazon.com/apigateway/home?region=us-east-2#/apis

crate-api

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 — https://us-east-2.console.aws.amazon.com/apigateway/home?region=us-east-2#/apis

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 — https://us-east-2.console.aws.amazon.com/apigateway/home?region=us-east-2#/apis 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 🔥 🔥

References:

vinay mavi

Written by

Full Stack Developer at @SapientNitro, Mentor, https://github.com/vinaymavi/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade