AWS

[Fixed] – Malformed Lambda proxy response – status 502

While executing the AWS lambda through the API gateway proxy URL, you may encounter an issue saying Malformed Lambda proxy response – Method completed with status: 502 here I am going to address the resolution for this.

Malformed Lambda proxy response:

When you see the Malformed Lambda proxy response, it means the response from the Lambda function doesn’t match the format of API Gateway is expecting.

issue:

Terminal
Wed Aug 04 16:57:22 UTC 2021 : Execution failed due to configuration error: Malformed Lambda proxy response
Wed Aug 04 16:57:22 UTC 2021 : Method completed with status: 502

Resolution:

Especially with API gateway proxy integrations, the API gateway requires a specific output format to be returned from the backend lambda function. Primarily the response should be in JSON format with the following fields init.

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

Example:

return {
        "statusCode": 200,
        "body": json.dumps({"statusCode": 200,"data": data}),
        "isBase64Encoded": False
    }

Done!

References:

Happy Learning:

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment

Our product

Preparing for an AWS, Azure or Google Cloud exam?

Take a free 20-question sample test with an explanation for every answer. No sign-up needed.

Start the free test