How do I resolve HTTP 502 errors from API Gateway REST APIs with Lambda proxy integration?

To Nha Notes | March 1, 2023, 2:45 p.m.

Resolution

For API Gateway to handle a Lambda function's response, the function must return output according to the following JSON format:

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}

 

References

https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format