API Gateway returns "502 Bad Gateway" and the logs say "Execution failed due to configuration error: Malformed Lambda proxy response".
BeginnerTroubleshooting5xx errors
Answer
Likely causes → With proxy integration, the Lambda must return an object with statusCode (number), optional headers, and body as a string. Returning a raw object, a non-string body, or throwing an unhandled error produces this.
Diagnose → Enable execution logging on the stage, then check the Lambda's own CloudWatch logs for the returned payload or exception.
Fix →
return {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": json.dumps(result)}
Wrap the handler so exceptions return a proper 500 response.
Prevent → Integration tests that invoke the function through API Gateway in staging, not just the handler in isolation.
More on 5xx errors
Right after a release, 500s spike to 8% and logs show `java.lang.NullPointerException` in a new code path.BeginnerLong-running report exports fail with "504 Gateway Time-out" from the ALB at exactly 60 seconds.Beginnernginx logs "upstream prematurely closed connection while reading response header from upstream" and users get 502.IntermediateEvery deploy causes 10–20 seconds of 502s from the ALB, even with a rolling update.IntermediateA Node.js service behind an ALB returns a steady trickle of 502s under normal load, with no app errors at all.AdvancedThrough Istio, clients get "503 upstream connect error or disconnect/reset before headers. reset reason: connection failure".Intermediate