Question

Difficulty: MediumAPI Development and Integration with Amazon API Gateway

A developer is configuring an Amazon API Gateway REST API that integrates with an external HTTP backend service. The client sends a GET request containing a query string parameter named `id`. The backend service requires a POST request with a JSON payload in the format `{"customerId": "value"}`. Which configuration should the developer implement in API Gateway to meet these requirements?

  1. Set the integration type to HTTP, set the integration method to POST, and configure an integration request mapping template for the application/json content type that extracts the ID using $input.params('id').Answer
  2. B
    Set the integration type to HTTP Proxy, set the integration method to POST, and configure method request parameter mapping to forward the ID query parameter.
  3. C
    Set the integration type to HTTP, configure a Lambda authorizer to extract the ID query parameter, and map it to the backend request headers.
  4. D
    Enable CORS on the resource, set the integration type to Mock integration, and define a response mapping template to forward the request body.

Answer

Set the integration type to HTTP, set the integration method to POST, and configure an integration request mapping template for the application/json content type that extracts the ID using the input params utility.
To transform an incoming GET request with a query parameter into a POST request with a JSON payload for an HTTP backend, the developer must use a custom HTTP integration. Under the integration request settings, the integration method is set to POST, and a mapping template for the application/json content type is defined. The VTL utility `$input.params('id')` is used to dynamically extract the query parameter value and insert it into the JSON request body.

Step-by-Step Solution

1
Determine the integration type requirements based on the backend communication pattern.
Since request transformation (converting GET query parameter to POST JSON body) is required for an external HTTP endpoint, a custom HTTP integration (non-proxy) must be selected.
Proxy integrations do not support request mapping templates.
2
Configure the integration request settings in API Gateway.
Set the integration method to POST to match the backend expectation.
This overrides the client's HTTP method for the backend invocation.
3
Create a mapping template for the application/json content type under Integration Request.
Define the VTL template mapping the customer ID: `{"customerId": "$input.params('id')"}`.
The utility function extracts the parameter from the request parameters (query string, path, or headers) and outputs it into the JSON payload body.

Key Concept

API Gateway integration request mapping templates allow developers to transform incoming client requests (e.g., query strings, headers) into the specific format and HTTP method required by a backend service.
Rate this question