API Gateway returns `502` with `{"message": "Internal server error"}`, and the execution log shows `Execution failed due to configuration error: Malformed Lambda proxy response`.
IntermediateTroubleshootingRoute 53, CloudFront, API Gateway and Messaging
Answer
Likely causes → With Lambda proxy integration, the function must return {"statusCode": int, "headers": {...}, "body": "<string>"}. A dict or object as body, a missing statusCode, or an unhandled exception all produce this error.
Diagnose →
aws apigateway update-stage --rest-api-id abc123 --stage-name prod \
--patch-operations op=replace,path=/*/*/logging/loglevel,value=INFO
aws logs tail API-Gateway-Execution-Logs_abc123/prod --since 10m
aws lambda invoke --function-name orders-api --payload fileb://event.json out.json && cat out.json
Fix → Return the exact proxy shape and serialize the body:
return {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": json.dumps(result)}
Catch exceptions and return a 500 response yourself.
Prevent → Use a framework (Powertools for AWS Lambda event handler) that builds responses, and add contract tests with a sample API Gateway event.
More on Route 53, CloudFront, API Gateway and Messaging
You created a public hosted zone and records for `example.com`, but `dig example.com` returns `NXDOMAIN` or old records.Beginner`InvalidChangeBatch: RRSet of type CNAME with DNS name example.com. is not permitted at apex in zone example.com.`BeginnerThe primary Region is down, but Route 53 failover records still send traffic to it.IntermediateA Route 53 health check reports `Failure: Connection timed out` for an endpoint that works fine from your laptop.IntermediateYou changed an A record an hour ago, but some users still reach the old server, and a newly created name returned `NXDOMAIN` for a while.AdvancedCloudFront returns `403 AccessDenied` (S3 XML) for every object after you switched the S3 origin to Origin Access Control.Intermediate