debugMajorpending
AWS Lambda timeout but function completes locally -- cold start and connections
Viewed 0 times
Lambda timeoutcold startVPCconnection reuseprovisioned concurrency
awsnodejspython
Error Messages
Problem
Lambda function works locally but times out in AWS. Or it sporadically times out after working fine. Increasing timeout to 30s does not help.
Solution
Common causes: (1) Cold start: first invocation initializes runtime. Keep functions small, use provisioned concurrency for latency-sensitive paths. (2) VPC cold start: Lambda in VPC creates ENI on cold start (10-30s penalty). Use VPC only when needed. (3) Database connections: creating new DB connections per invocation is slow. Reuse connections outside the handler. (4) DNS resolution: VPC DNS can be slow. (5) Waiting for event loop: Node.js Lambda waits for empty event loop by default. Set context.callbackWaitsForEmptyEventLoop = false.
Why
Lambda reuses execution environments across invocations. Resources initialized outside the handler persist. But cold starts create everything from scratch.
Revisions (0)
No revisions yet.