Build API Gateway with Lambda Integration

Lab Details

  1. This lab walks you through the steps to create an integration between Lambda and API Gateway
  2. You will practice using Amazon API Gateway.
  3. Duration: 45 minutes.
  4. AWS Region: US East (N. Virginia) us-east-1.

Introduction

Amazon API Gateway

  • Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. 
  • APIs act as the front door for applications to access data, business logic, or functionality from your backend services. 
  • API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, CORS support, authorization and access control, throttling, monitoring, and API version management. 
  • Using API Gateway, you can create RESTful APIs and WebSocket APIs that enable real-time two-way communication applications. API Gateway supports containerized and serverless workloads, as well as web applications. 
  • AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume.
  • With Lambda, you can run code for virtually any type of application or backend service – all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.     

Tasks

  1. Log into the AWS Management Console.
  2. Create a Lambda Function.
  3. Create a new API.
  4. Create a Resource.
  5. Create a Method.

Architecture Diagram

Lab Steps

Task 1: Launching Lab Environment

  1. Launch lab environment by clicking on . This will create an AWS environment with the resources required for this lab.
  2. Once your lab environment is created successfully,  will be active. Click on , this will open your AWS Console Account for this lab in a new tab. If you are asked to logout in AWS Management Console page, click on the here link and then click on  again.
  3. If you have logged into other aws accounts in the same browser, after clicking on the , you will be redirected to a page asking you to logout from the other aws account. 

 

Note : If you have completed one lab, make sure to sign out of the AWS account before starting a new lab. If you face any issues, please go through FAQs and Troubleshooting for Labs.

Task 2: Create a Lambda Function

  1. Navigate to the   menu at the top, then click on  under the  section.
  2. Click on the  button.
    • Choose .
    • Function name        : WhizlabsAPI
    • Runtime        : Select Python 3.8
    • Role            : In the permissions section, Choose   under change default execution role.
    • Enter the Role name as WhizlabsAPI, Choose policy template as Basic Lambda @ Edge Permission(For CloudFront Trigger)
    • Click on 
  3. Once the Lambda Function is created successfully, it will look like the screenshot below:

Task 3: Create an API

  1. Navigate to the    menu at the top, then click on    in the  section. 
  2. Click on  . If it gets started and is not visible, then click on  in REST API and select Protocol as REST.
  3. Choose to create a new API as . Under settings, choose the API name WhizlabAPI. Leave other options as default and click on     

Task 4: Creating a Resource

  1. Once the API is created, select the API and click on 
  2. Select  in actions.
  • Resource Name: Enter whizlabsapi
  1. Enter the resource name and click on 


Task 5: Creating a Method

  1. Once you create a resource, click on Actions, and select  . Select Get in the drop-down list.
  2. Select the Integration Type as 
  3. Enter the Lambda Function as WhizlabsAPI and choose the us-east-1 region. click on 
    • Note:  If any pop-ups appear, ignore them.
  1. Once the method has been created, your screen will look similar to the screenshot below:

Task 6: Deploy the  API

  1. Once the resource and the method have been created successfully, you can deploy the API.
  2. Click on  and select  under API actions.
  3. Select the Deployment Stage in the drop-down as New Stage.
  4. Enter Stage Name: TestingAPI  and Stage description as a Testing environment for my WhizlabsAPI.
  5. Click on 
  1. Once the API has been deployed, navigate to Stages. You will be able to see the following:
  1. Copy and Paste the Invoke URL (followed by the resource name) in the new tab to make a GET request.
  2. now add /whizlabsapi at the end of deploy URL.
  3. You will receive the GET request from the API. Here’s an example:

Task 7: Validation Test

  1. Once the lab steps are completed, please click on the  button on the right side panel.
  2. This will validate the resources in the AWS account and shows you whether you have completed this lab successfully or not.
  3. Sample output : 

Completion and Conclusion

  1. You have successfully created a Lambda function.
  2. You have successfully created the API.    
  3. You have successfully created the API Resource and Method.
  4. You have successfully tested the API.