One problem that pops up quite frequently when people try to build serverless applications with AWS API Gateway and AWS Lambda is Execution failed due to configuration error: Malformed Lambda proxy response.

There is nothing worse than generic error messages that don’t tell you anything you need to fix the problem, right? And AWS isn’t particularly known for its error message design, if you can even call it that, let alone for giving you the means of fixing the problem. So how to fix this Lambda error and what causes it?

Fixing malformed Lambda proxy response

In order to fix this, you need to change what your Lambda function returns. And to do so, you need to return an object with two attributes:

  • statusCode – which is the HTTP status code you want to give your client with type number.
  • body – which is the content of your HTTP response with type string.

If you used an asynchronous function, it should look like this:

exports.handler = async function(event, context) {
  return {statusCode: 200, body: "OK"};

#serverless #aws #aws-lambda #debugging #lambda

What Causes Malformed Lambda Proxy Response and How to Fix it
3.30 GEEK