Soru

Zorluk: KolayAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API in Amazon API Gateway that integrates with a backend AWS Lambda function. The developer needs the Lambda function to directly control the HTTP status code and headers returned to the API client. Which two configurations must be implemented to achieve this?

  1. Enable Lambda Proxy Integration on the API Gateway method integration.Cevap
  2. Ensure the Lambda function returns a JSON response containing the keys 'statusCode', 'headers', and 'body'.Cevap
  3. C
    Configure Integration Response mapping templates in the API Gateway console to map the backend response to the HTTP response.
  4. D
    Define the allowed HTTP status codes in the Method Response section in API Gateway.
  5. E
    Configure a custom Lambda Authorizer to rewrite the HTTP headers and status codes before they are sent to the client.

Cevap

To allow the Lambda function to control the HTTP status code and response headers, the developer must enable Lambda Proxy Integration on the API Gateway method integration, and the Lambda function must return a JSON response object containing the keys 'statusCode', 'headers', and 'body'.
To allow the Lambda function to control the response status codes and headers, the API Gateway integration must be configured for Lambda Proxy Integration. In this mode, API Gateway forwards the backend response directly to the client. The backend Lambda function must return the response in a standardized JSON payload format containing 'statusCode', 'headers', and 'body' so that API Gateway can correctly build the HTTP response.

Adım Adım Çözüm

1
Determine the integration type that delegates response control to the backend.
Lambda Proxy Integration is chosen.
Unlike Custom integration, Lambda Proxy Integration hands over control of the HTTP status codes, headers, and body formatting directly to the backend Lambda function.
2
Determine the output structure required from the Lambda function.
The Lambda function returns a JSON object with 'statusCode', 'headers', and 'body' properties.
API Gateway requires this specific JSON schema in Lambda Proxy mode so that it can parse the output and construct the final HTTP response for the API client.

Anahtar Kavram

API Gateway Lambda Proxy Integration response mapping and JSON output schema requirements
Bu soruyu puanla