Error Codes Wiki

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

Error5xx server error

About AWS API Gateway 504 Integration Timeout

Fix AWS API Gateway 504 timeout errors when the backend integration (Lambda, HTTP endpoint, or VPC link) exceeds the 29-second hard limit. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Optimize Lambda function execution: reduce processing time, use provisioned concurrency to eliminate cold starts. Move long-running operations to Step Functions or async Lambda invocations with callback URLs. For VPC-attached Lambdas, use VPC endpoints to avoid NAT gateway latency for AWS service calls. Implement connection pooling for database connections and reuse connections across invocations. Return an immediate 202 Accepted with a polling endpoint for operations expected to exceed 29 seconds. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Can I increase the 29-second timeout?

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.

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.