Question

Difficulty: MediumAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API using Amazon API Gateway. The backend integrates with an AWS Lambda function using a Lambda custom (non-proxy) integration. The client sends a GET request to the API with a query string parameter named `version`. The developer wants the Lambda function to receive a JSON payload structured exactly as `{"apiVersion": "<version_value>"}` in its input event.

Which configuration must the developer implement in API Gateway to satisfy this requirement?

  1. Configure an Integration Request body mapping template for the application/json content type that maps the query parameter using $input.params('version') to the apiVersion key.Answer
  2. B
    Enable Lambda proxy integration on the method and read the apiVersion key directly from the root of the event object in the Lambda function.
  3. C
    Configure a custom Lambda authorizer to extract the version query parameter and return it as apiVersion inside the validation context to the Lambda function.
  4. D
    Configure an Integration Response body mapping template in the API Gateway method settings to map the version query parameter to the apiVersion key.

Answer

Configure an Integration Request body mapping template for the application/json content type that maps the query parameter using $input.params('version') to the apiVersion key.
In a Lambda custom (non-proxy) integration, API Gateway does not automatically pass the raw request structure to the backend. Instead, the developer must define a mapping template under the Integration Request settings to construct the JSON payload that the Lambda function receives. The $input.params() function is used in the VTL mapping template to extract query parameters, headers, or path variables, allowing the creation of the required structure.

Step-by-Step Solution

1
Identify the integration type and mapping requirements.
The requirement is to map a query parameter from an incoming request to a custom JSON structure for a Lambda custom (non-proxy) integration.
Because Lambda custom integration requires the developer to explicitly map incoming request data to the backend payload using VTL templates.
2
Select the correct API Gateway configuration phase.
Choose the Integration Request phase to map the incoming client request before it is sent to the backend Lambda function.
The Integration Request is where request transformations occur, whereas the Integration Response is for backend-to-client transformations.
3
Define the mapping template.
Use the VTL utility method input.params() to extract the 'version' query parameter and output the desired JSON structure: {"apiVersion": " input.params('version')"}.
This extracts the parameter from the request metadata and generates the exact JSON structure required by the Lambda function.

Key Concept

API Gateway Integration Request Mapping Templates
Rate this question