What Causes Malformed Lambda Proxy Response and How to Fix it
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.
Understanding the Malformed Lambda proxy error response
If you have some time to spare, why not learn a bit about the “Why” of the error along the way?
First, Malformed Lambda proxy response isn’t really a configuration error because the problem lies in your Lambda code. But still, it could very well be that the routine that checks your return value also checks for other things that can be configured from the outside, like from AWS CloudFormation.