Photo: Sundry Photography / Shutterstock.com
Several cloud service providers these days allow developers to build and deploy serverless applications quickly. That said, as simple as the entire process has become, a few bugs and glitches still stump developers.
This article discusses the “Execution failed due to configuration error: malformed lambda proxy response” error when using AWS Lambda to deploy a serverless application.
Also read: Fix: HTTP error 502.5 – ancm out-of-process startup failure
What causes this error?
Contrary to what most developers believe, this isn’t exactly a configuration error as the issue lies in your Lambda code. The response generated by your Lambda function isn’t the one expected by the API gateway, hence causing the error

More specifically, you need to change the Lambda returns in your code so that they return an object with the following two attributes.
- statusCode: The HTTP code you want to give to the client to indicate the service’s status.
- body: The contents of your HTTP response.
Also read: What does Amazon Choice mean?
How to fix this?
Here are two fixes you can try out.
Bypass Lambda proxy integration checks
Provided you’re not using Lambda proxy integration, you can disable the integration sanity check performed by the service by logging into the API gateway console.
Do remember that this won’t solve the issue but simply doesn’t check for any request mismatches. If you take this solution, be absolutely sure that you won’t require Lambda proxy integration in the future. Otherwise, it’s recommended that you fix the issue completely before moving forward.
Fix the response format
As mentioned before, the main reason why you might experience this error is that your Lambda function isn’t responding in the format expected by the API gateway. Your response needs to include at least the statusCode and body attributes. An example response would look like this:
exports.handler = async function(event, context) {
return {statusCode: 200, body: "OK"};
};
If you’re using promised functions, your code will be as follows:
exports.handler = function(event, context) {
return new Promise(function(resolove, reject) {
resolve({statusCode: 200, body: "OK"});
});
};
Finally, if you’re using callbacks, try this:
exports.handler = function(event, context, callback) {
callback({statusCode: 200, body: "OK"});
};
Also read: What is Amazon Web Services (AWS) and how does it work?