# 504: Endpoint request timed out

AWS error fixes · Updated 16 November 2026

**Short answer:** Your integration (Lambda, an HTTP backend or a VPC link target) did not respond within the integration timeout, which defaults to 29 seconds for REST APIs and 30 seconds for HTTP APIs, so API Gateway gave up and returned 504. Make the backend respond faster, return early and finish the work asynchronously, or for Regional and private REST APIs request a longer integration timeout.

## What happens

```
HTTP/1.1 504 Gateway Timeout
x-amzn-ErrorType: InternalServerErrorException

{"message": "Endpoint request timed out"}
```

API Gateway waits for the integration up to its timeout, then answers the client itself. The backend is not cancelled: a Lambda function keeps running (and billing) until it finishes or hits its own timeout, and an HTTP backend keeps processing. That means a timed-out POST may still have done its work, so clients that retry can create duplicates.

## Causes, most common first

1. **Lambda cold start plus slow work**: heavy initialisation, a function in a VPC waiting on a database connection, or simply work that takes more than half a minute.
2. **Downstream dependency is slow**: database lock contention, a third-party API, a large report query.
3. **Backend unreachable**: an HTTP integration behind a security group that drops packets, or a VPC link whose targets are unhealthy. Requests hang until the timeout rather than failing fast.
4. **Integration timeout set lower than you think**: someone set `timeoutInMillis` on the integration to a few seconds.

## Find where the time goes

Compare `IntegrationLatency` (time spent waiting for the backend) with `Latency` (total). If both sit at about 29,000 ms for failing requests, the backend is the problem. Then check the integration's configured timeout:

```
aws apigateway get-integration --rest-api-id abc123 \
  --resource-id a1b2c3 --http-method POST \
  --query '{type:type,uri:uri,timeout:timeoutInMillis}'
```

For Lambda, line up the API's request time with the function's REPORT lines and look at `Duration` and `Init Duration`. An access log format that includes `$context.integrationLatency` and `$context.integration.status` makes this a one-query job; see [the API Gateway 5xx Logs Insights query](https://cloudconsole.dev/logs-insights/api-gateway-5xx-errors).

## Fixes

- **Fail fast in the backend.** Give database and HTTP clients timeouts well below the API's, and set the Lambda timeout just under the integration timeout, so the function logs a clear error instead of being cut off silently.

- **Go asynchronous for long work.** Accept the request, put the job on SQS or start a Step Functions execution, return 202 with a job ID, and let the client poll or receive a callback.

- **Remove cold-start delays** with provisioned concurrency for latency-sensitive functions, and move connection setup out of the handler path.

- **Fix reachability** for HTTP and VPC link integrations: check the target group health and security groups.

- **Raise the timeout only when justified.** Regional and private REST APIs can request an integration timeout above 29 seconds through Service Quotas (it can trade off against account throttle limits). Edge-optimised REST APIs and HTTP APIs cannot. Once allowed, set it per integration:

  ```
  aws apigateway update-integration --rest-api-id abc123 \
    --resource-id a1b2c3 --http-method POST \
    --patch-operations op=replace,path=/timeoutInMillis,value=60000
  aws apigateway create-deployment --rest-api-id abc123 --stage-name prod
  ```

## Confirm and prevent

After the fix, p99 `IntegrationLatency` should sit comfortably below the timeout, not just below it on average. Alarm on latency as well as on 5xx errors so you see the drift before requests start failing: see [IntegrationLatency alarm](https://cloudconsole.dev/alarms/api-gateway-integrationlatency) and [5XXError alarm](https://cloudconsole.dev/alarms/api-gateway-5xxerror). If CloudFront sits in front of the API, remember its origin response timeout is separate and can produce its own 504.

## Questions

### What is the API Gateway timeout limit?

By default 29 seconds for REST API integrations and 30 seconds for HTTP APIs. Regional and private REST APIs can request a higher integration timeout through Service Quotas.

### Does Lambda stop when API Gateway times out?

No. The function keeps running until it returns or reaches its own timeout, and you pay for that time. Set the function timeout close to the API's to avoid waste.

### Why do I get 504 only on the first request?

Usually a cold start: the function's initialisation plus the first request's work exceeds the timeout. Reduce init work or use provisioned concurrency.

## When this happens away from your desk

Timeouts tend to cluster at peak traffic, when a dependency slows down. CloudConsole, a phone app for AWS, is built to show latency and 5xx alarms with the slowest requests on your phone, so you can see which backend is dragging.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Amazon API Gateway quotas](https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html)
- [Amazon API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/)

## Related

- [Lambda: Task timed out after 3.00 seconds](https://cloudconsole.dev/errors/lambda-task-timed-out)
- [ALB 504 Gateway Timeout](https://cloudconsole.dev/errors/alb-504-gateway-timeout)
- [CloudWatch alarm for API Gateway IntegrationLatency (ApiId, Stage)](https://cloudconsole.dev/alarms/api-gateway-integrationlatency)
- [CloudWatch alarm for API Gateway 5XXError (REST API)](https://cloudconsole.dev/alarms/api-gateway-5xxerror)
- [How to increase Lambda timeout](https://cloudconsole.dev/how-to/increase-lambda-timeout)
- [API Gateway 5xx errors with Logs Insights](https://cloudconsole.dev/logs-insights/api-gateway-5xx-errors)

---

Source: https://cloudconsole.dev/errors/api-gateway-504-endpoint-request-timed-out

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
