Malformed Lambda proxy response ☁️ AWS

API Gateway {"message": "Internal server error"} 502 — Malformed Lambda proxy response

The Lambda behind an API Gateway proxy integration returned something that isn’t the required {statusCode, headers, body} shape, or it crashed.

Seen on: AWS

Meaning

With Lambda proxy integration, the function must return an object with statusCode (number) and body as a string. Returning an object as body, returning undefined (async handler without return), or the function erroring all produce a 502 “Internal server error” to the client. Execution logs show “Malformed Lambda proxy response”.

Common causes

  • body is an object instead of a JSON string
  • Missing statusCode
  • Handler throws or times out
  • Async handler returns before the promise resolves

⚡ Quick fix

  1. Return { statusCode: 200, headers, body: JSON.stringify(data) }
  2. Check the Lambda’s CloudWatch logs for exceptions
  3. Enable API Gateway execution logging

Detailed fix by platform

Node.js

  1. javascript
    export const handler = async () => ({
      statusCode: 200,
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ ok: true })
    });

How to diagnose

  1. Lambda logs — Errors/timeouts?
  2. Response — Shape returned
  3. Stage logs — "Malformed Lambda proxy response" present?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.