AWS Certified Developer – Associate (DVA-C02)Troubleshooting and MonitoringMedium

A developer is observing high latency and occasional 5xx errors from an API Gateway endpoint that integrates with a Lambda function. CloudWatch metrics for the Lambda function show low invocation errors, average duration well within limits, and sufficient concurrency. However, API Gateway's 'Latency' metric is high, and the '5XXError' metric is elevated. The Lambda function logs show successful executions for all triggered events. Which of the following is the MOST likely cause of the API Gateway errors and latency spikes?

  1. AThe API Gateway's throttling limits are being exceeded, causing requests to be rejected.
  2. BThe Lambda function's IAM role lacks permissions to be invoked by API Gateway.
  3. CThe API Gateway stage is configured with a low cache TTL, causing frequent cache misses.
  4. DThe integration timeout configured in API Gateway is shorter than the Lambda function's execution time for some requests.
Show answer & explanation

Correct answer: D. The integration timeout configured in API Gateway is shorter than the Lambda function's execution time for some requests.

If Lambda metrics show successful executions but API Gateway reports 5xx errors and high latency, it strongly suggests a mismatch in timeouts. If API Gateway's integration timeout is shorter than the Lambda's maximum execution time for some requests, API Gateway will time out and return a 504 error (a 5xx error) to the client, even if Lambda eventually succeeds. This also contributes to high API Gateway latency metrics as it waits for the timeout.

Why the other options are wrong

  • A. Exceeding throttling limits would result in 429 Too Many Requests errors, not 5xx errors (specifically 504 Gateway Timeout which is common in this scenario) or high latency for requests that eventually go through.
  • B. If Lambda's IAM role lacked invocation permissions, all API Gateway requests to Lambda would fail with a 5xx error (likely 500 Internal Server Error) consistently, not just occasionally with high latency.
  • C. A low cache TTL primarily affects performance and cost, not typically 5xx errors directly unless the backend is also failing under increased load.

API Gateway Integration Timeout

The API Gateway integration timeout defines the maximum amount of time API Gateway will wait for a backend integration (e.g., Lambda function, HTTP endpoint) to respond. If the backend does not respond within this period, API Gateway returns a 504 Gateway Timeout error to the client.

  • Default is 29 seconds for Lambda proxy integrations.
  • Can be configured up to 29 seconds for most integrations.
  • Must be carefully balanced with the backend service's expected response time.

Memory trick: API Gateway's 5XX: If the Integration Timeout is too short, the backend's too slow.

More Troubleshooting and Monitoring questions