AD PLACEMENT - LEADERBOARD
Back to all guides
AWS CloudWatch & JSON Data Formatting

Troubleshooting API Gateway 502 Errors Using CloudWatch Logs

What a 502 Means

API Gateway returns 502 Bad Gateway when the integration (usually Lambda) fails or returns a malformed response. CloudWatch captures the underlying cause.

Investigation Steps

  1. Open CloudWatch Logs for the integration's Lambda function.
  2. Look for the request ID matching the 502.
  3. Check for Task timed out, malformed response shape, or an unhandled exception.
  4. Confirm the Lambda response includes statusCode, headers, and a string body.

Malformed Response Example

{ "statusCode": 200, "body": { "ok": true } }

body must be a string, not an object. Fix:

{ "statusCode": 200, "body": "{\"ok\":true}" }

Use the FormatHub AWS CloudWatch Log Formatter to expand and compare these responses quickly.

AD PLACEMENT - STICKY FOOTER