Integrating AWS API Gateway with Lambda

Overview

Integrating AWS API Gateway with Lambda enables you to call Lambda functions from API Gateway. This article introduces how to integrate AWS API Gateway with Lambda.

Prerequisites

It is assumed that the Lambda function has already been created. If not, please refer to the following article for creation:

Deciding How to Integrate API Gateway with Lambda

When integrating API Gateway with Lambda, you need to consider the following two points:

  1. The request format for API Gateway
  2. Whether to use Proxy Integration or Non-Proxy Integration

Request Format for API Gateway

You can choose from the following formats:

  • REST API
  • HTTP API
  • WebSocket API

If you choose to use the REST API format, you will need to decide between REST API and HTTP API. While REST API has more features, it is more expensive than HTTP API. HTTP API is a good choice for simpler requirements.

For a detailed comparison, please refer to the official documentation.

Proxy vs. Non-Proxy Integration

Using Proxy Integration standardizes the format of the response returned from Lambda. It is generally recommended to use Proxy Integration.

Configuration

After creating the Lambda function, select “Add Trigger.”
Add Lambda Trigger

Choose API Gateway.
Select API Gateway

Configure the trigger addition as shown below. API Gateway Configuration

Once configured successfully, the screen should look like this.
API Gateway Configuration Complete

Access the API endpoint listed with a tool like curl to execute the Lambda function.

1
2
3
$ curl https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/default/apigateway-get-sample

"Hello from Lambda!"%

Summary

This article introduced how to integrate AWS API Gateway with Lambda. By integrating with API Gateway, you can externally invoke Lambda functions at any time.