AWS Certified Developer – Associate (DVA-C02) — Question 415
A developer is building an application integrating an Amazon API Gateway with an AWS Lambda function. When calling the API, the developer receives the following error:
Wed Nov 08 01:13:00 UTC 2017 : Method completed with status: 502
What should the developer do to resolve the error?
Answer options
- A. Change the HTTP endpoint of the API to an HTTPS endpoint.
- B. Change the format of the payload sent to the API Gateway.
- C. Change the format of the Lambda function response to the API call.
- D. Change the authorization header in the API call to access the Lambda function.
Correct answer: C
Explanation
An HTTP 502 (Bad Gateway) error in an Amazon API Gateway integration with AWS Lambda typically indicates that the Lambda function's output does not conform to the expected format required by the API Gateway proxy integration. To resolve this, the developer must ensure the Lambda function returns a properly structured JSON object containing keys such as 'statusCode', 'headers', and 'body'. Modifying the request payload, endpoint protocol, or authorization headers will not fix this response parsing issue.