AWS - API Gateway with Lambda

  Step 1: Create a NodeJs Lambda function         Select Lambda service and Click on Create function button         Select Author From Scrac...

 Step 1: Create a NodeJs Lambda function

  •         Select Lambda service and Click on Create function button
  •         Select Author From Scracth.
  •         Function name : ApiFunc
  •         Runtime: Node.js 14.x
  •         Permission ---> change default execution role
  •         select create new role from AWS policy Template
  •         and provide the role name apifuncrole

 Click on Create function button

Step 2: Use the below code for the Lambda function 

'use strict';

const https = require('https');
exports.handler = async (event) => {
    let dataString = '';

    const response = await new Promise((resolve, reject) => {
        const req = https.get("", function(res) {
          res.on('data', chunk => {
            dataString += chunk;
          res.on('end', () => {
                statusCode: 200,
                body: JSON.stringify(
                            "data": JSON.parse(dataString).title,
                            "timestamp": new Date()
                        }, null, 4
        req.on('error', (e) => {
              statusCode: 500,
              body: 'Something went wrong!'
    return response;

Then Click on  File--->save and Click on Deploy

Step 3: Create Rest API using API Gateway.

  •       Select API Gateway Service
  •       Click on Create API button
  •       Select RestAPI and click on Build button
  •       Select New API
  •       Api Name: myapi

  Click on Create Api Button.

Step 4: Create a Resource

  •           Select Action--> Create Resource
  •           Resource Name: what-is-my-title

     Click on Create Resource Button

Step 5: Select resource what-is-my-title and Goto Action---> Create Method from Drop down select Get Method and click on tick mark. 

Step 6: Click on Get Method 

  •            Integration Type: Lambda Function
  •           Select check box Use Lambda proxy Integration
  •           Lambda function: <<Lamda function name>> 

Click on Save button

Step 7: Select GET and Goto Action--->Deploy API

            Deployment Stage : New Stage

            Stage Name: api

Click on the Deploy button.

Step 8: You will find one Invoke URL on the top and open that URL in a new tab and at the end of the URL add what-is-my-title

  You will be able to see the title and current date and time

Step 9: Click on Export tab and select the Swagger and select Export as Swagger and click on json. It will download the json file for api Gateway.

Step 9: Take screen shot and copy IAM Role policy 



Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SDLC Quiz,3,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
DevOpsWorld: AWS - API Gateway with Lambda
AWS - API Gateway with Lambda
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content