Question

Difficulty: HardAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API in Amazon API Gateway using an HTTP custom (non-proxy) integration to connect to a legacy backend HTTP service. The API must map the backend service's 503503 Service Unavailable response to a 504504 Gateway Timeout client response. Additionally, the backend service requires the client's IP address to be sent in a custom header named `X-Forwarded-For-IP` derived from the API Gateway context. Which TWO configuration steps must the developer perform in API Gateway to meet these requirements?

  1. In the Integration Request settings, add a header parameter mapping for `X-Forwarded-For-IP` with a source of `context.identity.sourceIp`.Answer
  2. In the Method Response settings, define a 504504 HTTP status code, and in the Integration Response settings, create a mapping with an HTTP status regex of 503503 mapping to the 504504 method response status.Answer
  3. C
    Enable HTTP Proxy integration and use an API Gateway request mapping template to map the `X-Forwarded-For-IP` header from `$context.identity.sourceIp`.
  4. D
    In the Integration Response settings, map the HTTP status regex of 503503 to the 504504 method response status, and define the 504504 status code directly in the Integration Request settings.
  5. E
    Configure a custom Lambda authorizer to inject the `X-Forwarded-For-IP` header into the integration request and intercept the backend 503503 response to modify the status code.

Answer

In the Integration Request settings, add a header parameter mapping for `X-Forwarded-For-IP` with a source of `context.identity.sourceIp`. In the Method Response settings, define a 504504 HTTP status code, and in the Integration Response settings, create a mapping with an HTTP status regex of 503503 mapping to the 504504 method response status.
To forward the client's IP, the developer must use the Integration Request settings to map `X-Forwarded-For-IP` to the context variable `context.identity.sourceIp`. To map the status code, the developer must declare the 504504 response in the Method Response, and then create an Integration Response mapping with a regex of 503503 to translate the backend error code to the client response code.

Step-by-Step Solution

1
Set up parameter mapping in the Integration Request.
The `X-Forwarded-For-IP` header is populated with the value of the client source IP (`context.identity.sourceIp`) and forwarded to the backend.
Custom integrations allow headers to be injected or overridden using context variables before calling the backend.
2
Configure the Method Response status code.
A 504504 HTTP status is defined as a valid response code that the client can receive from this method.
API Gateway requires all status codes returned to the client to be declared in the Method Response first.
3
Map the backend status code to the Method Response in the Integration Response.
A backend 503503 response matches the regex, triggering the mapping to return a 504504 status code to the client.
This bridges the backend's response status code to the client's response status code.

Key Concept

API Gateway Custom HTTP Integration parameter and status mapping
Estimated Time:2m 30s
Rate this question