Lambda runs your handler function inside an execution environment. AWS creates these environments when requests arrive. Each environment handles only one request at a time. When more requests come in at the same time, Lambda adds more environments.
You pay per request, and for how long your code runs. The price of that time depends on the memory you configure. CPU power grows with memory too.
Design around these limits:
- One call can run for at most 15 minutes.
- Functions should be stateless (keep no data between calls), because AWS can reuse or throw away an environment at any time.
/tmpis temporary scratch space, not lasting storage.- A new environment has a cold start: extra startup time before your code runs.
- Concurrency (how many requests run at the same time) has a limit per account and per Region. A sudden burst of traffic can be throttled (rejected).
- Each environment opens its own database connections. Many environments can open too many connections for a relational database like PostgreSQL.
Put long-running or stateful work somewhere else, such as Step Functions, ECS or a queue.
- Each execution environment handles one request at a time. Lambda scales by adding environments.
- You pay per request and per running time. CPU grows with memory.
- One call can run for at most 15 minutes.
- Functions should be stateless, and /tmp is only temporary.
- Watch cold starts, concurrency limits and the number of database connections.
Read more