Question

Difficulty: MediumAPI Development and Integration with Amazon API Gateway

A developer is configuring an Amazon API Gateway REST API that integrates with an HTTP backend service hosted on-premises. The backend service requires a custom HTTP header named X-Backend-Token, which must be populated using the client's identity identifier found in the $context.authorizer.claims.sub context variable. Additionally, the backend service returns responses in XML format, but the API client expects a JSON payload.

Which two configurations must the developer implement in API Gateway to achieve this integration? (Select TWO.)

  1. Set the integration type of the API method to HTTP Integration.Answer
  2. In the Integration Request settings, map the X-Backend-Token header to context.authorizer.claims.sub.Answer
  3. C
    Set the integration type of the API method to HTTP Proxy Integration.
  4. D
    In the Method Request settings, map the X-Backend-Token header to context.authorizer.claims.sub.
  5. E
    In the Integration Response settings, define a mapping template for the application/xml content type to transform the XML payload to JSON.

Answer

Configure the integration type as HTTP Integration (non-proxy) and map the X-Backend-Token header to context.authorizer.claims.sub under the Integration Request settings.
The correct options are configuring the integration type to HTTP Integration and mapping the custom header under the Integration Request settings. HTTP Integration (custom integration) must be used instead of HTTP Proxy Integration because proxy integrations pass the client request and backend response directly through without modification, preventing any header injection or payload transformation. Mapping context variables to backend headers is configured in the Integration Request settings, which define the backend request structure.

Step-by-Step Solution

1
Determine the appropriate integration type for custom request modification and response payload transformation.
Choose HTTP Integration instead of HTTP Proxy Integration, because proxy integrations do not allow request parameter mapping or response body transformations.
An HTTP Integration (custom integration) allows API Gateway to map variables and apply mapping templates to request and response payloads.
2
Configure the custom header mapping from the authorizer context to the backend integration request.
In the API Gateway Console or CloudFormation, navigate to the Integration Request and add a header parameter mapping setting the name to 'X-Backend-Token' and the value to 'context.authorizer.claims.sub'.
The Integration Request is where incoming request data (and context variables) are mapped to backend integration arguments.
3
Configure the response transformation from XML to JSON.
Define a mapping template for the 'application/json' Content-Type in the Integration Response section to parse the XML from the backend and generate JSON.
API Gateway matches response mapping templates based on the client-side content type (Method Response), not the backend response content type.

Key Concept

Custom HTTP integration allows request header injection from context variables and response mapping templates for data transformation, which is not possible with proxy integrations.
Rate this question