A developer is building a serverless API where an Amazon API Gateway REST API is integrated with an AWS Lambda function using Lambda proxy integration. The Lambda function processes user data and returns a response. During testing, clients receive a Bad Gateway error. The Lambda execution logs show that the function ran successfully and completed without error. Which two changes should the developer make to the Lambda function's response to resolve this issue? (Select two.)
- Format the return value of the Lambda handler as a JSON object containing the statusCode and body fields.Cevap
- Ensure that the body field of the returned JSON object is serialized as a string.Cevap
- CConfigure integration response mapping rules in the API Gateway console to map the return value to an HTTP status code.
- DReturn a raw string response directly from the Lambda function handler.
- EAdd permission to the Lambda execution role to allow the apigateway:POST action.
Cevap
The developer should format the return value of the Lambda handler as a JSON object containing the statusCode and body fields, and ensure that the body field of the returned JSON object is serialized as a string.
For an Amazon API Gateway REST API utilizing Lambda proxy integration, the backend Lambda function must return a JSON response with a specific schema. This schema requires a 'statusCode' key (as an integer) and a 'body' key (which must be a string). If the function finishes successfully but returns a malformed structure or a non-string 'body' value, API Gateway cannot construct the HTTP response and returns a Bad Gateway error.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Lambda Proxy Integration Response Format