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 — 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 👏 👏
Create an API 🔌
STEP 1 — Goto — API Gateway home — https://us-east-2.console.aws.amazon.com/apigateway/home?region=us-east-2#/apis
STEP 2 — Click CreateAPI button and insert required details
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
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.
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 ⚡️
STEP 6 — select GET method from dropdown and click Test button.
Expected output
{
"statusCode": 200,
"body": "\"Hello from Lambda!\""
}
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
STEP 2 — Click Actions drop down => click Deploy API
STEP 3 — select [new State]
Enter stage details and click Deploy button.
STEP 4 — Goto to stages and click “Invoke URL”
Expected output
Congratulations you public api is ready 🔥 🔥
References: