Task timed out ☁️ AWS

AWS Lambda: Task timed out after X seconds

The function ran longer than its configured timeout (default 3 seconds) and Lambda stopped it.

Seen on: AWS Node.js Python

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

  1. Raise the timeout (up to 15 min) to a realistic value
  2. Add NAT gateway or VPC endpoints for VPC Lambdas
  3. Set client timeouts shorter than the Lambda timeout
  4. Node: context.callbackWaitsForEmptyEventLoop = false for pooled DB connections

Detailed fix by platform

AWS

  1. 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

  1. Duration — CloudWatch REPORT line: Duration vs timeout
  2. Network — In a VPC? NAT/endpoints?
  3. 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.