Error Codes Wiki

AWS API Gateway 504 Integration Timeout — Lambda or Backend Response Too Slow

Error5xx server error

Overview

Fix AWS API Gateway 504 timeout errors when the backend integration (Lambda, HTTP endpoint, or VPC link) exceeds the 29-second hard limit.

Key Details

  • API Gateway REST APIs have a hard 29-second timeout limit that cannot be increased
  • API Gateway HTTP APIs have the same 29-second maximum integration timeout
  • WebSocket APIs have a 29-second timeout for route integrations but support 2-hour idle connection timeout
  • The 504 is returned when the Lambda function or backend does not respond within the timeout
  • This timeout includes Lambda cold start time, so cold starts on heavy functions can cause timeouts

Common Causes

  • Lambda function processing time exceeds 29 seconds due to heavy computation or slow dependencies
  • Backend HTTP endpoint behind a VPC link is slow or unreachable
  • Lambda function stuck waiting on a database connection from an exhausted connection pool
  • Cold start of a Lambda function in a VPC taking 10+ seconds, leaving insufficient time for processing

Steps

  1. 1Optimize Lambda function execution: reduce processing time, use provisioned concurrency to eliminate cold starts
  2. 2Move long-running operations to Step Functions or async Lambda invocations with callback URLs
  3. 3For VPC-attached Lambdas, use VPC endpoints to avoid NAT gateway latency for AWS service calls
  4. 4Implement connection pooling for database connections and reuse connections across invocations
  5. 5Return an immediate 202 Accepted with a polling endpoint for operations expected to exceed 29 seconds

Tags

api-gatewayaws504lambdatimeout

Related Items

More in 5xx Server Error

Frequently Asked Questions

No. The 29-second timeout is a hard limit for API Gateway REST and HTTP APIs. It cannot be increased even on Enterprise support plans. Redesign your architecture for async processing if you need longer operations.