Amazon Web Services · api · fg-0170

API Gateway REST API returns 502 Bad Gateway with Malformed Lambda proxy response though the Lambda succeeded

If you see {"message": "Internal server error"} with HTTP 502, the cause and the fix for Amazon Web Services are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
{"message": "Internal server error"} with HTTP 502Execution log: Execution failed due to configuration error: Malformed Lambda proxy responseLambda returns a plain object or a body that is an object
Cause
A REST API proxy integration only accepts a response object with statusCode, optional headers, and body as a string. Any other shape, including an object body, becomes a 502.
Fix
Return statusCode and a JSON string body from the handler, and add CORS headers there because proxy integrations do not add them.
Apply
export const handler = async () => ({ statusCode: 200, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, body: JSON.stringify({ ok: true }), });
Affected
REST APIs (v1) with Lambda proxy integration (type AWS_PROXY), whose response shape is fixed; HTTP APIs only when the integration uses payload format version 1.0, since 2.0 infers a response from plain JSON
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun