"Lambda runs anything, instantly." Not quite. The first request to a function can be noticeably slower than the rest, and every function lives inside hard limits on time, memory and payload size. This is the last of three parts on Lambda.
What a cold start is
Before your handler can run, Lambda needs an execution environment. When none is free, it creates one: it downloads your code, starts the runtime, and runs your initialization code, everything outside the handler such as imports and database connections. That preparation is the cold start.
Afterwards the environment is kept for a while and reused. Requests that land on it are warm starts and skip the setup.
AWS says cold starts typically affect a small share of invocations and last from under 100 milliseconds to over a second, depending mostly on your own code. They show up when a function is called rarely, right after a deployment, and when traffic jumps and Lambda has to add environments.
Reducing cold starts
- Keep the package small. Import only what you need. Large dependencies and heavy setup code are the main cause.
- Initialize once. Create SDK clients and connections outside the handler so warm requests reuse them.
- SnapStart. Lambda initializes the function when you publish a version, takes a snapshot, and resumes new environments from it. It is available for supported Java, Python and .NET runtimes; check the pricing for your runtime.
- Provisioned concurrency. Lambda keeps a number of environments initialized and ready. Start-up becomes predictable, but you pay for those environments whether they are used or not.
Don't pay for provisioned concurrency by reflex. Measure first: background jobs rarely care about a one-second start.
The limits to design around
Current values from the Lambda quotas page, for standard functions:
- Timeout: at most 15 minutes (900 seconds) per invocation.
- Memory: 128 MB to 10,240 MB. CPU is allocated in proportion to memory.
- Payload: 6 MB for a synchronous request and for a normal (buffered) response; 1 MB for an asynchronous event.
- Deployment package: 250 MB unzipped for a .zip, or a container image up to 10 GB.
- Concurrency: a per-Region quota on how many environments run at once. The default is 1,000, new accounts can start lower, and it can be raised. See service quotas.
Exceed the timeout and the run is stopped. Exceed concurrency and requests are throttled. Work that doesn't fit, such as long batch jobs or large file transfers through the function, belongs in another tool: a container service, AWS Step Functions, or Lambda's newer options for longer workflows.
Where AI fits
Generating an answer with a large language model takes seconds, and a buffered Lambda response makes the user wait for all of it. Response streaming lets a function send the response in pieces as they are produced, so the first words appear almost immediately. That improves time to first byte, not total time, but it is what makes a chat interface feel fast.
Details that matter:
- Streaming works through Lambda function URLs, the
InvokeWithResponseStreamAPI, and Amazon API Gateway's streaming integration. - It is supported natively on the Node.js managed runtimes; other languages need a custom runtime or the Lambda Web Adapter.
- Streamed responses can be far larger than 6 MB (up to 200 MB at the time of writing).
- You are billed for the full duration even if the client disconnects, so keep timeouts sensible.
Quick recap
- A cold start is the setup before the first request on a new environment.
- Stay small or stay warm: trim the package, use SnapStart, or pay for provisioned concurrency.
- Know the limits: 15 minutes, about 10 GB of memory, 6 MB responses, and a concurrency quota.