Coding⏱️ 3 min read📅 2026-06-03

How to Fix: AWS Lambda API Gateway error: "Malformed Lambda proxy response"

Quick Answer: The issue is caused by the incorrect use of callback in the Lambda function. The correct syntax should be callback(null, { message: 'Hello World' });

The 'Malformed Lambda proxy response' error occurs when the AWS Lambda function returns an invalid or malformed response to API Gateway. This issue affects developers who are using API Gateway to deploy their Lambda functions, particularly those who are new to serverless computing.

This error can be frustrating because it prevents the API Gateway from successfully deploying and serving your Lambda function. However, by following the steps outlined in this guide, you should be able to resolve the issue and get your API Gateway up and running again.

💡 Why You Are Getting This Error

  • The primary cause of the 'Malformed Lambda proxy response' error is that the Lambda function returns a response with an incorrect or missing content type header. This can happen when the Lambda function does not specify a content type in its response, or when the response contains invalid characters.
  • Another possible cause of this error is that the Lambda function returns a response with an incorrect HTTP status code. For example, if the Lambda function returns a 404 Not Found status code instead of a 200 OK status code, API Gateway will not be able to successfully deploy and serve the function.

✅ Best Solutions to Fix It

Specify Content Type in Lambda Function Response

  1. Step 1: Open your Lambda function code and locate the export statement for the handler function.
  2. Step 2: Modify the callback function to include a content type header in its response. For example, you can add the following line of code to specify a JSON content type: `callback(null, { 'Hello': 'World' }, { statusCode: 200, headers: { 'Content-Type': 'application/json' } });`.
  3. Step 3: Save your Lambda function code and redeploy it to API Gateway. This should resolve the 'Malformed Lambda proxy response' error.

Verify HTTP Status Code in Lambda Function Response

  1. Step 1: Open your Lambda function code and locate the export statement for the handler function.
  2. Step 2: Modify the callback function to return a valid HTTP status code. For example, you can add the following line of code to specify an HTTP status code: `callback(null, { 'Hello': 'World' }, { statusCode: 200 });`.
  3. Step 3: Save your Lambda function code and redeploy it to API Gateway. This should resolve the 'Malformed Lambda proxy response' error.

🎯 Final Words

By following these steps and understanding the root causes of the 'Malformed Lambda proxy response' error, you should be able to successfully deploy and serve your AWS Lambda function through API Gateway.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions