Question

Difficulty: HardAPI Development and Integration with Amazon API Gateway

An engineering team is building a REST API using Amazon API Gateway that integrates with a legacy HTTP backend service using an HTTP integration (non-proxy). When the legacy backend cannot find a record, it returns an HTTP status code 404 with a plain text error message. The team wants the API Gateway to intercept this 404 response and instead return an HTTP status code 200 to the client, containing a structured JSON payload: {"available": false, "reason": "Record not found"}. Which configuration steps must the developer perform in API Gateway to meet these requirements?

  1. A
    Configure the API Gateway method to use an HTTP Proxy integration, and set up a Gateway Response for the 404 status code to rewrite the HTTP status code to 200 and inject the custom JSON payload.
  2. B
    In the Method Response configuration, create a response mapping rule with a regex of 404 and specify the custom JSON mapping template. In the Integration Response configuration, add a method response with a status code of 200.
  3. In the Method Response configuration, ensure the 200 status code is defined. In the Integration Response configuration, create a mapping rule with an HTTP status regex of 404, map it to the 200 method response, and define an application/json mapping template to output the custom JSON payload.Answer
  4. D
    Configure an Amazon Cognito User Pool authorizer to intercept the legacy HTTP backend's response, validate the OAuth scopes, and transform the 404 status code into a 200 status code with the custom JSON payload.

Answer

In the Method Response configuration, ensure the 200 status code is defined. In the Integration Response configuration, create a mapping rule with an HTTP status regex of 404, map it to the 200 method response, and define an application/json mapping template to output the custom JSON payload.
To transform a backend response's status code and body in a non-proxy integration, you must first define the target status code (200) in the Method Response. Then, in the Integration Response, you map the backend's response status code (404) to the target Method Response status code (200) and specify a mapping template to output the required JSON format. This decouples the client-facing API contract from the legacy backend implementation.

Step-by-Step Solution

1
Define the target HTTP status code in the Method Response configuration.
The API Gateway method is configured to allow a client-facing HTTP 200 response.
Before mapping any integration response to a client response status, that status code must exist in the Method Response configuration.
2
Configure the Integration Response mapping rule for HTTP 404.
API Gateway intercepts backend HTTP 404 responses and redirects them to the 200 Method Response path.
The HTTP status regex in the Integration Response matches the incoming backend status code to direct it to the appropriate client status code.
3
Specify an application/json mapping template in the Integration Response.
The backend plain text body is transformed into the desired JSON format.
Mapping templates (VTL) reshape backend payloads to conform to the client's expected interface.

Key Concept

API Gateway Integration Response Mapping
Estimated Time:2m 0s
Rate this question