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 invokes a Lambda function. The Lambda function logs indicate successful execution within milliseconds, and CloudWatch metrics for Lambda show no errors or throttling. However, API Gateway metrics for the endpoint show a high 'IntegrationLatency' and '5XXError' rate. Which of the following is the MOST likely cause of the issue?

  1. AThe API Gateway stage cache is misconfigured, leading to stale or incorrect responses.
  2. BThe Lambda function is taking too long to return a response to API Gateway, exceeding the API Gateway integration timeout.
  3. CThe Lambda function's IAM role does not have permission to be invoked by API Gateway.
  4. DThe backend Lambda function is experiencing cold starts, which are not reflected in its own execution metrics.
Show answer & explanation

Correct answer: B. The Lambda function is taking too long to return a response to API Gateway, exceeding the API Gateway integration timeout.

If Lambda logs show quick execution but API Gateway shows high 'IntegrationLatency' and 5xx errors, it strongly suggests the Lambda function is not returning the response to API Gateway within the configured integration timeout. Even if the Lambda finishes quickly, if it doesn't return the *response* to API Gateway in time (e.g., due to network issues or incorrect response formatting causing a delay in API Gateway processing), API Gateway will time out and return a 504 Gateway Timeout (a 5xx error).

Why the other options are wrong

  • A. A misconfigured cache would lead to incorrect data or cache misses, not typically 5xx errors from integration timeouts.
  • C. If IAM permissions were the issue, API Gateway would likely return a 403 Forbidden error, not a 5xx from an integration timeout.
  • D. Lambda cold starts would be reflected in the Lambda function's duration metrics and potentially lead to longer execution times, which the question states are 'within milliseconds'.

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 return a response before it times out and returns a 504 Gateway Timeout error to the client.

  • Default is 29 seconds for proxy integrations, 50ms to 29s for non-proxy.
  • API Gateway returns 504 Gateway Timeout if exceeded.
  • Distinct from Lambda execution timeout.

Memory trick: API Gateway's 'Integration Timeout' is a strict boss; don't make it wait!

More Troubleshooting and Monitoring questions