Soru

Zorluk: OrtaAPI Development and Integration with Amazon API Gateway

A developer is designing a REST API in Amazon API Gateway. The API uses request validation with a model schema to ensure incoming client payloads are correctly structured. If a client sends an invalid request body or fails to provide a valid API key, API Gateway rejects the request before it reaches the backend integration. The developer wants to customize these gateway-level error responses to return a standard JSON error structure and inject a custom tracking header (X-Request-Tracking-Id) into the HTTP response.

Which two configurations should the developer implement in API Gateway to meet these requirements? (Select TWO.)

  1. In the API configuration, customize the Gateway Responses for the specific error types, such as Bad Request Body and Unauthorized, and define the custom JSON body templates.Cevap
  2. Under the Gateway Responses configuration, use response parameters to define the custom header mapping for the desired error types.Cevap
  3. C
    Configure an Integration Response for the API methods to capture client validation failures and map the response header and template.
  4. D
    Create a custom Lambda Authorizer that validates the request body schema and returns a serialized JSON error response with the custom tracking header.
  5. E
    Modify the Method Response settings of the resource to define the mapping templates and header mappings for 400 and 403 status codes.

Cevap

To customize gateway-level errors in Amazon API Gateway, the developer should customize the Gateway Responses for the specific error types (such as Bad Request Body and Unauthorized) with custom JSON body templates, and use response parameters under the Gateway Responses settings to define the custom tracking header.
Gateway Responses are generated directly by API Gateway before the request is sent to the integration backend (e.g., when request validation fails or authentication fails). A developer can customize these responses at the API level by modifying the response templates for specific Gateway Response types (such as Bad Request Body or Unauthorized) to return custom JSON. In addition, the developer can add custom headers using response parameters, mapping them to context variables or static values.

Adım Adım Çözüm

1
Identify where the request validation and authentication failures are processed.
The failures occur at the gateway level (before forwarding to backend integration).
This determines that Gateway Responses, rather than Integration Responses or Method Responses, must be configured.
2
Configure the custom JSON response body for these gateway-level failures.
Modify the Gateway Responses configuration for the API, selecting specific response types (e.g., BAD_REQUEST_BODY, UNAUTHORIZED) and defining the application/json template.
This ensures the client receives a structured JSON payload instead of the default API Gateway error message.
3
Configure the custom tracking header in the response.
Add response parameters inside the target Gateway Responses to map the custom header (X-Request-Tracking-Id) to a static value or a context variable.
This ensures the header is appended to the response returned directly from API Gateway.

Anahtar Kavram

API Gateway Gateway Responses customization for error handling
Tahmini Süre:1m 30s
Bu soruyu puanla