Create API Gateway and Integrate with Lambda

Objective

Connect AWS API Gateway with a Lambda Function to create a RESTful endpoint that allows accessing data stored in DynamoDB.


Implementation Steps


1. Access API Gateway

  • Go to AWS Console → API Gateway
  • Click Create API

API_1

  • Select REST API (Build)

API_2

  • Configure:
    • Create new API: New API
    • API name: FlyoraAPI
    • Endpoint type: Regional
  • Click Create API

API_3


2. Create Resources and Methods

  1. In the sidebar, select
    Actions → Create Resource

API_4

  • Resource Name: api
  • Click Create Resource

API_5


  1. Select /api → Actions → Create Resource

  1. Configure the resource:
  • Resource path: /api/
  • Resource Name: v1
  • Click Create Resource

API_14


  1. Create a proxy resource under /api
  • Check Proxy resource
  • Resource path: /api/
  • Resource Name: {proxy+}
  • Click Create Resource

API_18


  1. Select /v1 → Actions → Create Resource

Configure:

  • Check Proxy resource
  • Resource path: /api/v1/
  • Resource Name: {myProxy+}
  • Click Create Resource

API_15


  1. Enable CORS for all resources

API_CORS

Under OPTIONS → Integration response → Header Mappings, ensure the headers below exist:

  • Access-Control-Allow-Origin: *
  • Access-Control-Allow-Headers:
    Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
  • Access-Control-Allow-Methods:
    DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT

API_Headers


3. Integrate with Lambda

  1. After creating /api/v1/{myProxy+}, the ANY method appears:
    • Select ANY → Integration request → Edit

API_16


  1. Attach Lambda:
  • Integration type: Lambda Function
  • Check Lambda proxy integration
  • Lambda Region: ap-southeast-1 (Singapore)
  • Lambda Function: select your Lambda_API_Handler

API_17


4. Deploy API

  • Select Actions → Deploy API
  • Deployment stage: New stage
    • Stage name: dev
    • Description: Development stage for Lambda API
  • Click Deploy

API_9


After deployment, you will receive an Invoke URL in the format:

https://<api_id>.execute-api.ap-southeast-1.amazonaws.com/dev