I built an API Gateway REST API with Lambda Integration



I created an API using the API Gateway console that allows a client to call Lambda functions via the Lambda integration.

Before creating the API, set up the Lambda backend by creating a Lambda function in AWS Lambda.

Create Lambda Function

    1. Sign in to the Lambda console at https://console.aws.amazon.com/lambda.
    2. On the AWS navigation bar, choose a region Note: Note the region where you create the Lambda function. You'll need it when you create the API.
    3. Choose Functions in the navigation pane.
    4. Choose Create function.
    5. Choose Author from scratch.

Under Function code source, write your code in the inline code editor

Choose Deploy

Create API Gateway

Now create an API for your Lambda function by using the API Gateway console.

Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway Choose Create API. Under REST API, choose Build.

Under Create new API, choose New API. Under Settings: For API name, enter "API name". Enter a description in the Description field or leave it empty. Leave Endpoint Type set to Regional. Choose Create API.

Create the resource as follows:

Choose the root resource (/) in the Resources tree.

    • Choose Create Resource from the Actions dropdown menu.
    • Leave Configure as proxy resource unchecked.
    • For Resource Name, enter "resource_name".
    • Leave Resource Path set to /resource_name.
    • Leave Enable API Gateway CORS unchecked.
    • Choose Create Resource.

The whole request is transmitted to the backend Lambda function through a proxy integration, using a catch-all ANY method that represents any HTTP method. The client specifies the actual HTTP method at run time. The ANY method enables you to utilize a single API method configuration for all available HTTP methods, including DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT.

To set up the method, do the following:

  • In the Resources list, choose /"resource_name".
  • In the Actions menu, choose Create method.
  • Choose ANY from the dropdown menu, and choose the checkmark icon

  • Leave the Integration type set to Lambda Function.
  • Choose Use Lambda Proxy integration.
  • From the Lambda Region dropdown menu, choose the region where you created the Lambda function.
  • In the Lambda Function field, type any character and choose the Lambda function from the dropdown menu.
  • Leave Use Default Timeout checked.
  • Choose Save.
  • Choose OK when prompted with Add Permission to Lambda Function.

Deploy API

Deploy the API in the API Gateway console

  • Choose Deploy API from the Actions dropdown menu.

  • For the Deployment stage, choose [new stage].

  • For the Stage name, enter "test_stage".
  • If desired, enter a Stage description.
  • If desired, enter a Deployment description.
  • Choose Deploy.
  • Note the API's Invoke URL.