AWS lambda api gateway error "Malformed Lambda proxy response"

amazon-web-services, aws-api-gateway, aws-lambda, node.js

Solution

Usually, when you see `Malformed Lambda proxy response`, it means your response from your Lambda function doesn't match the format API Gateway is expecting, like this

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

If you are not using Lambda proxy integration, you can login to API Gateway console and uncheck the Lambda proxy integration checkbox.

Also, if you are seeing intermittent `Malformed Lambda proxy response`, it might mean the request to your Lambda function has been throttled by Lambda, and you need to request a concurrent execution limit increase on the Lambda function.

Problem

I am trying to set up a hello world example with AWS lambda and serving it through api gateway. I clicked the "Create a Lambda Function", which set up the api gatway and selected the Blank Function option. I added the lambda function found on AWS gateway getting started guide: ``` exports.handler = function(event, context, callback) { callback(null, {"Hello":"World"}); // SUCCESS with message }; ``` The issue is that when I make a GET request to it, it's returning back a 502 response `{ "message": "Internal server error" }`. And the logs say "Execution failed due to configuration error: Malformed Lambda proxy response".

Original source