Soru

Zorluk: KolayAPI Development and Integration with Amazon API Gateway

A developer is implementing a new backend service using an Amazon API Gateway REST API with a Lambda proxy integration. To ensure that API Gateway can successfully process the response and forward it to the client, the Lambda function must return a JSON payload with a specific structure. Which JSON payload structure must the Lambda function return to represent a successful HTTP response?


  1. {
    "isBase64Encoded": false,
    "statusCode": 200,
    "headers": {
    "Content-Type": "application/json"
    },
    "body": "{\"message\": \"Success\"}"
    }
    Cevap
  2. B

    {
    "statusCode": 200,
    "body": {
    "message": "Success"
    }
    }
  3. C

    {
    "httpStatus": 200,
    "message": "Success"
    }
  4. D

    {
    "headers": {
    "Content-Type": "application/json"
    },
    "body": "{\"message\": \"Success\"}"
    }

Cevap

The correct JSON structure contains `isBase64Encoded`, `statusCode`, `headers`, and a stringified `body` field.
The correct payload contains a status code of 200200, headers, and a stringified JSON body. For Lambda proxy integrations, API Gateway expects a response with a numeric `statusCode`, key-value `headers` map, and a string-formatted `body` property.

Adım Adım Çözüm

1
Analyze the integration type configured in API Gateway.
The integration type is Lambda proxy integration.
This determines whether API Gateway automatically parses the output (custom integration) or requires a strict pre-defined JSON payload structure (proxy integration).
2
Identify the mandatory response parameters for Lambda proxy integrations.
The backend Lambda function must return `statusCode` (integer), `headers` (map of string to string), and `body` (string).
These fields are parsed directly by API Gateway to construct the HTTP response for the client.
3
Verify the datatype of the `body` field.
The payload in the `body` field must be serialized as a string.
API Gateway does not parse a JSON object directly inside the `body` field; passing an object instead of a string results in a 502502 Bad Gateway error.

Anahtar Kavram

Lambda Proxy Integration Response Format
Tahmini Süre:45s
Bu soruyu puanla