Soru

Zorluk: OrtaAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API in Amazon API Gateway to integrate with a backend AWS Lambda function. The API client requires a custom header named `X-Custom-Header` in the HTTP response, and the response body must be formatted in JSON. The developer decides to use a Lambda proxy integration to minimize API Gateway configuration overhead. Which two actions must the developer perform to ensure the client receives the expected response?

  1. Enable the Lambda proxy integration option in the API Gateway Method Execution settings.Cevap
  2. Format the return object of the Lambda function to include a `headers` object with the `X-Custom-Header` key-value pair and stringify the JSON payload in the `body` field.Cevap
  3. C
    Configure an Integration Response mapping template in API Gateway to parse the Lambda function output and inject the `X-Custom-Header` header.
  4. D
    Configure a Gateway Response in API Gateway to append the `X-Custom-Header` header to all 200 OK responses.
  5. E
    Use a custom Lambda authorizer to inject the `X-Custom-Header` value into the context object and map it using a Method Response header setting.

Cevap

Enable the Lambda proxy integration option in the API Gateway Method Execution settings, and format the return object of the Lambda function to include a `headers` object with the `X-Custom-Header` key-value pair and stringify the JSON payload in the `body` field.
The correct options involve enabling Lambda proxy integration in the method settings and constructing the response object correctly inside the Lambda function code. In a Lambda proxy integration, API Gateway passes the response directly from the Lambda function to the client without applying mapping templates. Therefore, the Lambda function itself must return the custom header in its response object's `headers` block and stringify the output payload under the `body` property.

Adım Adım Çözüm

1
Analyze the integration type requirement.
The requirement specifies using Lambda proxy integration to minimize API Gateway configuration overhead.
Lambda proxy integration passes requests and responses through without modification by API Gateway mapping templates.
2
Determine the API Gateway configuration.
The developer must check the Lambda proxy integration option in the Integration Request settings for the API method.
This sets up the proxy integration pattern.
3
Determine the backend Lambda response format.
The Lambda function must return a JSON object containing `statusCode` (integer), `headers` (map of string to string), and `body` (stringified JSON).
API Gateway requires this specific output format from a proxy integration to construct the HTTP response for the client.

Anahtar Kavram

Amazon API Gateway Lambda Proxy Integration response format and configuration
Bu soruyu puanla