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.
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
- Return { statusCode: 200, headers, body: JSON.stringify(data) }
- Check the Lambda’s CloudWatch logs for exceptions
- Enable API Gateway execution logging
Detailed fix by platform
Node.js
- javascript
export const handler = async () => ({ statusCode: 200, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ok: true }) });
How to diagnose
- Lambda logs — Errors/timeouts?
- Response — Shape returned
- 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:
Similar errors
Most viewed in AWS
Other ways to find it
🧠 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.
Report a correction or suggest an improvement
Last updated 8 Oct 2026