Skip to content

How to Fix AWS API Gateway 504 Integration Timeout

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix AWS API Gateway 504 Integration Timeout. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Your API Gateway endpoint returns 504 Endpoint Request Timed Out — the integration (Lambda, HTTP, or VPC Link) did not respond within the timeout limit.

Step-by-Step Fix

1. Check integration timeout settings

aws apigateway get-integration --rest-api-id abc123 --resource-id def456 --http-method POST

Look for the timeoutInMillis field (default is 29000 ms, max is 29000 for Lambda):

{
    "timeoutInMillis": 29000,
    "type": "AWS_PROXY"
}

2. Increase API Gateway timeout (HTTP integration only)

aws apigateway update-integration --rest-api-id abc123 --resource-id def456 --http-method POST --patch-operations op=replace,path=/timeoutInMillis,value=29000

3. Optimize Lambda for faster response

import json

def lambda_handler(event, context):
    result = quick_computation(event)
    return {
        "statusCode": 200,
        "headers": {"Content-Type": "application/json"},
        "body": json.dumps(result)
    }

4. Use asynchronous integration

Configure the Lambda to return immediately and process in the background:

{
    "type": "AWS",
    "httpMethod": "POST",
    "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:my-function/invocations",
    "credentials": "arn:aws:iam::123456789012:role/APIGatewayLambdaRole",
    "requestTemplates": {
        "application/json": "{\"statusCode\": 200}"
    }
}
aws apigatewayv2 get-vpc-link --vpc-link-id vpce-12345678

Common Mistakes

Mistake Fix
Lambda function timeout < 29s Increase Lambda timeout in function config
VPC Link target unreachable Check NLB target group health
Lambda not in same region Ensure all services are in the same region
HTTP integration timeout set to 0 Set a positive timeout value
No response from backend Check backend server access logs

Prevention

  • Set Lambda timeout to less than 29 seconds for API Gateway.
  • Use WebSocket API for real-time streaming.
  • Enable API Gateway Caching to reduce Lambda calls.
  • Monitor integration latency with CloudWatch.

Common Mistakes with API Gateway 504

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the API Gateway integration timeout limit?

The maximum integration timeout for REST and HTTP APIs is 29 seconds. For WebSocket APIs, the maximum is 10 seconds for the connection route. |||Can I increase the API Gateway timeout beyond 29 seconds? No, 29 seconds is the hard limit. For longer operations, use an asynchronous pattern where the Lambda returns a 202 response and processes in the background. |||Why does my Lambda work in tests but timeout in API Gateway? The Lambda may work within the 15-minute Lambda limit in tests, but API Gateway enforces its own 29-second timeout. Optimize the Lambda to respond within 29 seconds.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro