Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS lambda api gateway error "Malformed Lambda proxy response"

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".

like image 882
jjbskir Avatar asked Apr 30 '17 15:04

jjbskir


People also ask

What is Lambda proxy?

The Lambda proxy integration allows the client to call a single Lambda function in the backend. The function accesses many resources or features of other AWS services, including calling other Lambda functions.

Does API gateway retry Lambda?

At runtime, API Gateway matches the Lambda error's errorMessage against the pattern of the regular expression on the selectionPattern property. If there is a match, API Gateway returns the Lambda error as an HTTP response of the corresponding HTTP status code.


2 Answers

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.

like image 55
Ka Hou Ieong Avatar answered Sep 23 '22 14:09

Ka Hou Ieong


If lambda is used as a proxy then the response format should be

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

Note : The body should be stringified

like image 40
selftaught91 Avatar answered Sep 22 '22 14:09

selftaught91