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?
- 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
- BSet the integration type to HTTP Proxy, set the integration method to POST, and configure method request parameter mapping to forward the ID query parameter.
- CSet the integration type to HTTP, configure a Lambda authorizer to extract the ID query parameter, and map it to the backend request headers.
- DEnable 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
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.