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.

All Real-World Interview questions Roadmap: Interview readiness

More on 5xx errors