Amazon Web Services · api · fg-0170

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

{"message": "Internal server error"} with HTTP 502

Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100

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 }),
});

Affects: 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

Have your agent know this before it fails

claude mcp add --transport http footgun https://getfootgun.com/api/mcp