Learn this hands-on: covered in Week 6: Serverless and containers of our 12-week AWS Solutions Architect Associate (SAA-C03) course, with live labs and a trainer to help. See the full syllabus →

Read the logs first
REPORT RequestId: 1a2b... Duration: 3003.12 ms Billed Duration: 3000 ms
Memory Size: 128 MB Max Memory Used: 127 MB Init Duration: 812.45 ms
... Task timed out after 3.00 seconds Duration equal to the timeout confirms it. Max Memory Used close to Memory Size suggests the function needs more memory. A large Init Duration points to slow start-up code.
Causes and fixes
| Cause | Fix |
|---|---|
| Default 3-second timeout too low | Raise it to realistic time plus a margin (API Gateway still cuts off at 29 seconds by default) |
| Lambda in a VPC calls the internet or an AWS API | Add a NAT gateway route, or VPC endpoints (S3, DynamoDB, Secrets Manager) |
| Slow database or API call | Set client timeouts shorter than the Lambda timeout, add retries, reuse connections, use RDS Proxy |
| Too little memory | Increase memory; CPU grows with memory, so the function often gets faster and costs the same |
| Cold start with heavy init | Move clients outside the handler, trim packages, use SnapStart (Java/Python/.NET) or provisioned concurrency |
| Waiting on an empty event loop (Node.js) | Make sure promises are awaited; close open handles |
Fix it step by step
- Open the CloudWatch log group
/aws/lambda/<function>and find the timed-out invocation. - Add simple timing logs around each external call to see which one is slow, or turn on X-Ray tracing.
- If the function is in a VPC, check: does it really need to be? If yes, check the subnets route to a NAT gateway or that VPC endpoints exist for the services it calls.
- Set the SDK or HTTP client timeout lower than the function timeout so you get a clear error instead of a silent timeout.
- Increase memory (for example 128 MB → 512 MB) and compare Duration; use AWS Lambda Power Tuning to find the cheapest setting.
- Raise the function timeout only after the real cause is fixed.
When Lambda is the wrong tool
Jobs that take longer than 15 minutes, or that wait on long downloads, fit better in Step Functions (to split the work), ECS Fargate tasks or AWS Batch.
Questions
What is the maximum Lambda timeout?
15 minutes (900 seconds). The default for new functions is 3 seconds.
Why does my Lambda work locally but time out in AWS?
Very often it is VPC networking: inside a VPC the function has no internet access unless the subnet routes through a NAT gateway.