AWS Lambda Timeout: The 15-Minute Limit, How to Increase It and Fix "Task timed out"
"Task timed out after 3.00 seconds" means your Lambda function was still running when it hit its timeout. New functions created in the console start with a 3-second timeout, and the maximum is 900 seconds (15 minutes). Raise it under Configuration → General configuration, but also find out why it is slow: a function in a VPC that cannot reach S3 or the internet, a slow database query or connection, too little memory (which also means less CPU), or a job that is simply too long for Lambda.
Quick answer
aws lambda update-function-configuration --function-name orders-report --timeout 60
aws lambda update-function-configuration --function-name orders-report --memory-size 1024
aws logs tail /aws/lambda/orders-report --since 15m # read the timing
A live example first
A Python function orders-report reads a CSV from S3 and writes a summary to DynamoDB. In testing it fails:
START RequestId: 5c1e... Version: $LATEST
END RequestId: 5c1e...
REPORT RequestId: 5c1e... Duration: 3003.45 ms Billed Duration: 3000 ms
Memory Size: 128 MB Max Memory Used: 71 MB
2026-10-16T18:41:07Z 5c1e... Task timed out after 3.00 seconds
We add simple timing logs:
import time, boto3
s3 = boto3.client("s3")
def handler(event, context):
t = time.time()
obj = s3.get_object(Bucket="rb-orders-2026", Key="oct.csv")
print("s3 get took", round(time.time() - t, 2), "s")
With the timeout raised to 30 seconds, the log shows the S3 call never returns. The function is attached to a VPC (to reach RDS) in private subnets with no NAT gateway, so it cannot reach the S3 endpoint at all.
The fix: add an S3 gateway VPC endpoint to the private route table (free) and a DynamoDB gateway endpoint. Now:
s3 get took 0.21 s
REPORT ... Duration: 1840.12 ms Memory Size: 128 MB
Then we raise memory to 512 MB. The same work finishes in about 600 ms. Friends, raising the timeout only showed us the problem. The endpoint fixed it.
Why does Lambda time out?
Raise the timeout, but find why it waits: network in a VPC, a slow database, low memory, or a job that needs splitting.
Lambda stops your function when the configured timeout is reached, whatever it is doing. Common reasons:
| Cause | Sign in logs | Fix |
|---|---|---|
| Timeout too low (3 s default) | Work is real but needs longer | Raise the timeout |
| VPC with no route to AWS/internet | Hangs on the first SDK or HTTP call | NAT gateway or VPC endpoints |
| Slow database / new connection each time | Long waits on connect or query | RDS Proxy, connection reuse, indexes |
| Low memory = low CPU | Heavy CPU, high duration | Increase memory |
| Waiting on a slow external API | Time spent in HTTP call | Set client timeouts, retry, go async |
| Job is just long | Steady progress, runs > 15 min | Split the work |
How do I fix it step by step?
- Open CloudWatch Logs for the function and read the
REPORTline (duration, memory used). - Raise the timeout to a sensible value (for example 30 or 60 seconds) to see the full picture.
- Add timing logs around each external call, or turn on X-Ray active tracing.
- If the function is in a VPC, check the subnets' route tables for a NAT gateway or endpoints.
- Create SDK and database clients outside the handler so they are reused.
- Try more memory (512 MB, 1024 MB) and compare duration and cost.
- Set the timeout to a little above the normal duration, not the maximum, so stuck runs end quickly.
Fixes by runtime
Python (boto3)
Create clients at module level, and set client timeouts so a stuck call fails fast:
from botocore.config import Config
s3 = boto3.client("s3", config=Config(connect_timeout=3, read_timeout=10, retries={"max_attempts": 3}))
Node.js
Create the SDK v3 client outside the handler. Do not leave open handles (timers, DB connections) that keep the event loop busy. If you use callbacks with open connections, set context.callbackWaitsForEmptyEventLoop = false.
Java (Spring Cloud Function, plain handlers)
Cold starts can take seconds. Use SnapStart (for supported Java runtimes) or a larger memory size, and keep the initialisation work small.
.NET and Go
.NET benefits from more memory and ReadyToRun or Native AOT builds. Go functions start quickly; time-outs there are almost always network or downstream waits.
Databases (MySQL, PostgreSQL on RDS)
Each new connection takes time, and hundreds of concurrent functions can exhaust the database. Put RDS Proxy in front, reuse one connection per container, and add indexes for slow queries.
When 15 minutes is not enough
| Option | Use it when |
|---|---|
| Step Functions | The job has clear steps, each under 15 minutes |
| SQS + Lambda | You can split the data into many small messages |
| ECS Fargate / AWS Batch | One task really needs a long time or a lot of memory |
| Glue | Big data transforms (ETL) |
Also remember API Gateway's own integration timeout (29 seconds by default for REST APIs) and the Application Load Balancer timeout. For long work behind an API, accept the request, put it on SQS, return 202 Accepted, and let the client check a status URL.
Real example: right tool for the job
In 2023, the Amazon Prime Video team published a blog post about a video-quality monitoring service first built with AWS Step Functions and Lambda. At their scale, the many function calls and data transfers cost too much, and they moved that part into a single ECS service, reporting about 90% lower infrastructure cost for it. The lesson is not "avoid Lambda". It is: Lambda is great for short, event-driven tasks. Long or very chatty jobs may fit containers better.
Mistakes to avoid
- Setting every function to 900 seconds. A stuck function then burns 15 minutes of cost each time.
- Putting Lambda in a VPC without need. Only attach a VPC if it must reach private resources.
- Creating clients inside the handler. You pay connection time on every call.
Summary table
| Item | Value / action |
|---|---|
| Default timeout (console) | 3 seconds |
| Maximum timeout | 900 seconds (15 minutes) |
| Change it | Configuration → General configuration, or update-function-configuration --timeout |
| VPC hang | NAT gateway or VPC endpoints |
| Slow DB | RDS Proxy, reuse connections, indexes |
| CPU-bound | More memory |
| Longer jobs | Step Functions, SQS, ECS Fargate, Batch |
Quick quiz: check what you learned
What is the maximum timeout for an AWS Lambda function?
- 900 seconds
- 300 seconds
- 3600 seconds
- 60 seconds
Show answer
A. Lambda functions can run for up to 15 minutes.
A VPC Lambda hangs calling S3. What is the likely cause?
- No NAT or VPC endpoint
- Too much memory set
- A wrong runtime version
- Missing environment file
Show answer
A. Private subnets need a route to reach AWS service endpoints.
Why can more memory make a Lambda faster?
- CPU grows with memory
- Disk grows to 10 TB
- The timeout doubles too
- Network is turned off
Show answer
A. Lambda allocates CPU power in proportion to memory.
API Gateway returns 504 at about 29 s. What fits best?
- Return fast, process async
- Raise Lambda to 900 s
- Delete the API stage
- Switch the region now
Show answer
A. The API has its own limit, so long work should run asynchronously.
Learn it properly
These pages go deeper, with labs:
Frequently asked questions
What is the default and maximum Lambda timeout?
The default is 3 seconds when you create a function in the console. The maximum is 900 seconds (15 minutes).
How do I increase the Lambda timeout?
In the console go to Configuration → General configuration → Edit → Timeout, or run aws lambda update-function-configuration --function-name NAME --timeout 60.
Why does my Lambda time out when calling S3 or DynamoDB?
If the function is in a VPC private subnet without a NAT gateway or VPC endpoint, it cannot reach AWS service endpoints and waits until the timeout.
Why does API Gateway return 504 before Lambda finishes?
API Gateway has its own integration timeout (29 seconds by default for REST APIs). Make the request return fast and process the rest asynchronously.
Does more memory make Lambda faster?
Often, yes. Lambda gives CPU in proportion to memory, so CPU-heavy code finishes faster, and the cost can stay similar.
What if my job needs more than 15 minutes?
Split it into steps with Step Functions, process items in batches from SQS, or run it as a container on ECS Fargate or AWS Batch.