AWS Lambda: Task timed out after X seconds
The function ran longer than its configured timeout (default 3 seconds) and Lambda stopped it.
Meaning
Lambda’s default timeout is only 3 seconds. Beyond slow code, the classic causes are network calls that hang (Lambda in a VPC without a NAT gateway can’t reach the internet), cold starts, and open DB connections keeping the event loop alive in Node.
Common causes
- Default 3s timeout too low
- Lambda in a VPC calling the internet without NAT / VPC endpoints
- Slow downstream API or database
- Node.js event loop kept alive by open connections (callbackWaitsForEmptyEventLoop)
- Cold start + heavy initialisation
⚡ Quick fix
- Raise the timeout (up to 15 min) to a realistic value
- Add NAT gateway or VPC endpoints for VPC Lambdas
- Set client timeouts shorter than the Lambda timeout
- Node:
context.callbackWaitsForEmptyEventLoop = falsefor pooled DB connections
Detailed fix by platform
AWS
- Update timeout and memory (more memory = more CPU):bash
aws lambda update-function-configuration --function-name orders-api --timeout 30 --memory-size 512
How to diagnose
- Duration — CloudWatch REPORT line: Duration vs timeout
- Network — In a VPC? NAT/endpoints?
- Downstream — X-Ray: which call is slow?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026