Interview Prep/AWS/Route 53, CloudFront, API Gateway and Messaging

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.

aws All AWS questions Roadmap: AWS core services

More on Route 53, CloudFront, API Gateway and Messaging