Home / AWS

AWSTroubleshootingIntermediate

AWS Lambda timeouts and throttling: diagnosis and fixes

Tell timeouts from throttles using CloudWatch metrics and logs, then fix them with the right timeout, memory, concurrency and VPC settings.

Deepak Bhardwaj2 min read

Applies toAWS Lambda (all runtimes), API Gateway, SQS and EventBridge triggers

What the customer sees

Symptom Likely cause
Task timed out after N seconds in the logs The function exceeded its timeout
API Gateway 504 after 29 s API Gateway's integration timeout, even if Lambda's own timeout is longer
Rate exceeded / TooManyRequestsException / HTTP 429 Throttling: concurrency limit reached
SQS messages reprocessed or in the DLQ Timeouts plus visibility timeout misconfiguration

Metrics to check

aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Throttles \
  --dimensions Name=FunctionName,Value=orders-api --statistics Sum \
  --start-time "$(date -u -d '-3 hours' +%FT%TZ)" --end-time "$(date -u +%FT%TZ)" --period 300

Look at Duration (p99 against the timeout), Throttles, ConcurrentExecutions, Errors, and IteratorAge for stream triggers.

Timeouts

# Find slow invocations with Logs Insights
aws logs start-query --log-group-name /aws/lambda/orders-api \
  --start-time $(date -d '-1 hour' +%s) --end-time $(date +%s) \
  --query-string 'filter @type = "REPORT" | stats max(@duration), pct(@duration, 99), avg(@maxMemoryUsed/1000000) by bin(5m)'

Fixes:

  • Give it more memory. CPU scales with memory, so 512 MB → 1,769 MB gives a full vCPU and often cuts duration a lot.
  • Downstream calls: set client timeouts shorter than the function timeout, so you get a clear error instead of a silent timeout.
  • Initialize outside the handler (SDK clients, DB connections) so warm invocations reuse them.
  • VPC functions that call the internet or AWS APIs need a NAT gateway or VPC endpoints. Without them, calls hang until the timeout.

Throttling

aws lambda get-account-settings --query "AccountLimit.{concurrent:ConcurrentExecutions,unreserved:UnreservedConcurrentExecutions}"
aws lambda get-function-concurrency --function-name orders-api
  • The account has a regional concurrency limit (often 1,000 by default; check yours). One busy function can starve the others. Use reserved concurrency to protect critical functions, and to cap noisy ones.
  • A reserved concurrency of 0 disables the function. Check that nobody set it by mistake.
  • For predictable spikes, use provisioned concurrency to avoid cold starts and burst limits.
  • Request a quota increase through Service Quotas if sustained demand is higher than the limit.

SQS-triggered functions

  • Set the queue's visibility timeout to at least 6× the function timeout, so in-flight messages aren't redelivered while they're still being processed.
  • Use maximum concurrency on the event source mapping to protect downstream databases.
  • Always configure a DLQ or on-failure destination, and alarm on its depth.

Tip

Use Lambda Powertools (structured logging, tracing, metrics) and turn on X-Ray tracing. Most "Lambda is slow" tickets turn out to be one slow downstream call, and the trace shows it immediately.