
People worry about two things with serverless. The first request might be slow, and the bill might be a surprise.
Both worries are fair, and both depend on things that are easy to miss. How often you hit a cold start depends on the shape of your traffic. And in the example bill below, Lambda's own charges are the smallest part.
This post uses AWS Lambda and US East (N. Virginia) list prices, checked against AWS's pages in November 2026. Prices vary by region and change over time, so check yours. The simulations use made-up traffic and stated assumptions. They show how the pieces fit together, and they don't predict your numbers.
What a cold start is
Your function runs inside an execution environment, a small isolated container that Lambda sets up for you. When a request arrives and no ready environment is free, Lambda builds a new one.
It then runs your start-up code before it handles the request. That start-up work is called the INIT phase, and the delay it causes is a cold start.
Later requests that reuse a started environment skip INIT and run only your handler. Lambda also builds new environments when traffic grows. INIT has a ten-second limit.
How common are cold starts? AWS's analysis of production workloads found that they typically happen in under 1 percent of invocations, and last from under 100 ms to over 1 second. Whether your function sits below that figure or far above it is what the next section tests.
What cold starts cost
Since August 1, 2025, INIT time counts toward the billed duration for functions that use ZIP packaging and a managed runtime. Before that date it was free for them. Functions with custom runtimes, Provisioned Concurrency, or container packaging were already billed for it.
AWS gives an example. A function reported 250.06 ms of duration and 100.77 ms of init time. It was billed 251 ms before the change and 351 ms after.
AWS expects minimal impact for most users, because INIT happens for a small share of invocations. The bill example later in this post agrees.
How often will you hit one?
The simulator below follows AWS's model. Each environment handles one request at a time. A request uses a free, warm environment if one exists. Otherwise Lambda creates a new one, and that request pays for a cold start.
When many requests arrive at the same moment, each one needs its own environment, so each one is cold. AWS describes this too.
Idle environments are retired after 10 minutes in the simulation. That number is a guess. AWS only says that Lambda shuts down idle environments after a period of inactivity. Save the code as cold_sim.py:
"""Simulate how many requests hit a cold start, given a pattern of arrivals."""
import random
def simulate(arrivals, service_s=0.2, init_s=0.4, idle_timeout_s=600):
"""Each environment handles one request at a time. A request reuses a warm, free
environment if one exists; otherwise a new one is created (a cold start).
Idle environments are dropped after `idle_timeout_s` (an assumption; real lifetimes vary)."""
free_at = [] # when each existing environment becomes free
cold = peak = 0
for t in arrivals:
free_at = [f for f in free_at if not (f <= t and t - f > idle_timeout_s)]
ready = [i for i, f in enumerate(free_at) if f <= t]
if ready:
i = max(ready, key=lambda k: free_at[k]) # reuse the most recently used one
free_at[i] = t + service_s
else:
cold += 1
free_at.append(t + init_s + service_s)
peak = max(peak, sum(1 for f in free_at if f > t))
return {"requests": len(arrivals), "cold": cold, "peak_concurrency": peak}
def poisson(rate, duration_s, seed=1):
rng, t, out = random.Random(seed), 0.0, []
while True:
t += rng.expovariate(rate)
if t > duration_s:
return out
out.append(t)
def bursts(size, every_s, duration_s):
return [k * every_s + i * (1.0 / size) for k in range(int(duration_s // every_s)) for i in range(size)]
def every(seconds, duration_s):
return [k * seconds for k in range(int(duration_s // seconds))]Here are four traffic patterns over six hours, with 200 ms requests and 400 ms of init time:
from cold_sim import simulate, poisson, bursts, every
H = 6 * 3600 # six hours, in seconds
print(simulate(poisson(2.0, H))) # steady, random arrivals at 2 req/s
print(simulate(bursts(240, 120, H))) # 240 requests within a second, every 2 minutes
print(simulate(bursts(1800, 900, H))) # 1,800 requests within a second, every 15 minutes
print(simulate(every(900, H))) # one request every 15 minutesPattern | Average rate | Requests | Cold starts | Peak concurrency |
|---|---|---|---|---|
Steady, random arrivals | 2 req/s | 43,011 | 25 (0.06%) | 6 |
Burst of 240 requests every 2 minutes | 2 req/s | 43,200 | 148 (0.34%) | 145 |
Burst of 1,800 requests every 15 minutes | 2 req/s | 43,200 | 25,937 (60%) | 1,081 |
One request every 15 minutes | 0.001 req/s | 24 | 24 (100%) | 1 |
The first three rows have the same average rate, yet the share of cold starts runs from 0.06 percent to 60 percent.
What decides it is the gap between bursts, compared with how long idle environments survive. Bursts every 2 minutes keep the environments alive, so only the first burst pays. Bursts every 15 minutes find everything retired and start from scratch each time.
The last row is the classic complaint. A rarely used endpoint is cold on every call. That costs almost nothing, but it feels slow, because no warm environment is ever waiting.
To find your own rate, look at the REPORT line that Lambda writes for each invocation. It includes an Init Duration value only when the invocation was a cold start. Count those lines and divide by all REPORT lines. With Lambda Insights turned on, there is also an init_duration metric.
Ways to shrink the problem
Do less at start-up. AWS advises keeping ZIP packages small, removing unused dependencies, and trimming initialization code, because big packages and heavy imports slow every cold start.
Give the function more memory. More memory also means more CPU, which AWS says can shorten initialization and often improves cold start performance.
Try SnapStart. AWS describes it as an effective way to cut cold start latency and INIT cost.
Use Provisioned Concurrency for steady, latency-sensitive traffic. It keeps environments initialized ahead of requests, for an extra charge.
Pinging a function on a schedule to keep it warm is not a reliable fix. AWS notes that it doesn't help when traffic scales up, because the new environments still start cold.
A cost model you can check
Lambda charges for requests and for duration. Duration is measured in GB-seconds: the memory you configure, in gigabytes, times the billed seconds.
These are the list prices used in this post. The code below saves as lambda_cost.py.
Item | US East price |
|---|---|
Lambda requests | $0.20 per million |
Lambda duration, x86 | $0.0000166667 per GB-second |
Lambda duration, Arm | $0.0000133334 per GB-second |
Lambda free tier | 1 million requests and 400,000 GB-seconds per month |
API Gateway, HTTP API | $1.00 per million (first 300 million) |
API Gateway, REST API | $3.50 per million (first 333 million) |
Lambda logs in CloudWatch Logs | $0.50 per GB (first 10 TB per month) |
"""Monthly cost model for a Lambda-backed API. US East (N. Virginia) list prices, first tier."""
REQUEST_PER_MILLION = 0.20
GB_SECOND = {"x86": 0.0000166667, "arm": 0.0000133334}
FREE_REQUESTS = 1_000_000
FREE_GB_SECONDS = 400_000
API_PER_MILLION = {"http": 1.00, "rest": 3.50} # API Gateway
LOG_PER_GB = 0.50 # Lambda logs sent to CloudWatch Logs
def lambda_cost(requests, avg_ms, memory_mb, arch="x86",
cold_starts=0, init_ms=0.0, free_tier=True):
"""Lambda's own charges. INIT time is billed like normal duration (since Aug 1, 2025)."""
gb_seconds = memory_mb / 1024 * (requests * avg_ms + cold_starts * init_ms) / 1000
billable_gbs = max(gb_seconds - FREE_GB_SECONDS, 0) if free_tier else gb_seconds
billable_req = max(requests - FREE_REQUESTS, 0) if free_tier else requests
return {"compute": billable_gbs * GB_SECOND[arch],
"requests": billable_req / 1e6 * REQUEST_PER_MILLION}
def monthly_bill(requests, avg_ms, memory_mb, api=None, log_kb=0.0, **kwargs):
"""Lambda plus the services around it. `api` is 'http', 'rest', or None."""
bill = lambda_cost(requests, avg_ms, memory_mb, **kwargs)
if api:
bill["api gateway"] = requests / 1e6 * API_PER_MILLION[api]
if log_kb:
bill["logs"] = requests * log_kb / 1024 / 1024 * LOG_PER_GB
bill["total"] = sum(bill.values())
return bill
def breakeven_requests(fixed_monthly_cost, avg_ms, memory_mb, **kwargs):
"""Monthly request count at which the serverless bill reaches a fixed monthly price."""
lo, hi = 0, 10**10
while hi - lo > 1000:
mid = (lo + hi) // 2
if monthly_bill(mid, avg_ms, memory_mb, **kwargs)["total"] < fixed_monthly_cost:
lo = mid
else:
hi = mid
return loTo check the model against AWS, it reproduces two of AWS's own worked examples.
The first is 3 million requests at 120 ms and 1,536 MB, which costs $2.33 for compute and $0.40 for requests, $2.73 in total. The second is one million 32-second runs at 1 GB on Arm, which costs $421.34 for compute.
It also matches the INIT example above. A duration of 250.06 ms plus 100.77 ms of init rounds up to 351 billed milliseconds.
Memory is a speed dial that can be free
Lambda gives CPU power in proportion to memory. You can set anything from 128 MB to 10,240 MB, and at 1,769 MB the function gets the equivalent of one full vCPU.
So a CPU-bound function can finish faster at higher memory while costing about the same. Take a single-threaded function that needs 2,000 ms at 128 MB. Assume its speed grows with CPU share up to one vCPU:
from lambda_cost import lambda_cost
for mb in (128, 256, 512, 1024, 1769, 3008):
ms = 2000 * 128 / min(mb, 1769) # assumed: speed scales with CPU share up to 1 vCPU
cost = lambda_cost(1_000_000, ms, mb, free_tier=False)
print(mb, round(ms), round(sum(cost.values()), 2))The cost includes $0.20 of request charges per million and ignores the free tier.
In this model, the cost is $4.37 per million invocations at every setting from 128 MB to 1,769 MB. Over that range the duration falls from 2,000 ms to 145 ms, a factor of 14.
Past one vCPU the extra memory buys nothing, because a single thread can't use more CPU. At 3,008 MB the duration is still 145 ms and the cost jumps to $7.28, about two-thirds more.
Nothing in that table was measured, and real functions behave differently. AWS says that CPU-bound, network-bound, and memory-bound functions can all gain from more memory. A function that mostly waits on another service may gain little.
AWS points to the open-source AWS Lambda Power Tuning tool. It runs your function at several memory settings and measures the result.
The bill around the function
Now add the services that usually sit in front of and beside the function. Take 10 million requests a month at 120 ms and 512 MB on x86.
Assume 0.2 percent of requests are cold starts with 400 ms of init, and 2 KB of logs per request, which is about 19 GB a month. Count no free tiers other than Lambda's:
from lambda_cost import monthly_bill
for api in ("http", "rest"):
bill = monthly_bill(10_000_000, 120, 512, api=api, log_kb=2,
cold_starts=20_000, init_ms=400)
print(api, {k: round(v, 2) for k, v in bill.items()})Line item | With HTTP API | With REST API |
|---|---|---|
Lambda compute | $3.40 | $3.40 |
Lambda requests | $1.80 | $1.80 |
API Gateway | $10.00 | $35.00 |
Logs | $9.54 | $9.54 |
Total | $24.74 | $49.74 |
Lambda's own charges come to $5.20. The API in front costs about twice that with an HTTP API and nearly seven times that with a REST API. Logging costs almost twice what Lambda does.
The INIT time for those 20,000 cold starts adds only 4,000 GB-seconds, about seven cents. At this rate, cold starts are a latency problem and hardly a cost problem.
The figures depend on the assumptions, but the pattern is clear in this example. The function is cheap, and the services around it are not.
A few levers help. Use an HTTP API unless you need REST features. It charges less than a third as much per request, though it meters requests in 512 KB steps, so a large payload counts as several.
Logs are billed when they are written, so how much you log matters. Lambda can also send logs to S3 or Firehose, which starts at $0.25 per GB, half the CloudWatch rate.
When does always-on win?
On-demand Lambda pricing grows roughly in line with traffic. So above some request rate, a fixed-price server is cheaper. The breakeven_requests function finds that point.
Take a hypothetical server at $30 a month. Count API Gateway (HTTP) and logs on the serverless side. The break-even in this example is about 11.7 million requests a month, or 4.5 requests per second on average.
Swap in your real server price and your real duration, memory, and log size. The comparison leaves out the work of running a server, and whether it would sit idle much of the time. Use it as a first filter and expect to refine it.
What the simulation and model leave out
The simulator assumes unlimited, instant scaling and a fixed 10-minute idle timeout. It ignores concurrency and scaling limits on your account, so a burst of a thousand environments may behave differently in practice.
The bill leaves out data transfer, networking charges such as NAT gateways, and Provisioned Concurrency.
AWS also applies tiered discounts to on-demand duration above certain monthly usage, and the model ignores them.
All prices are US East list prices, and free tiers other than Lambda's are ignored.
Before you change anything
Find your cold-start rate from the
Init Durationvalues in your logs. See whether it is closer to 0.1 percent or 50 percent.Break your bill down by line item, and look at API Gateway and logs next to Lambda.
Test memory settings with Power Tuning. The right setting depends on what limits your function.
Reach for SnapStart or Provisioned Concurrency only when the measured tail latency justifies the extra cost or complexity.
References
AWS Compute Blog, AWS Lambda standardizes billing for INIT Phase: the August 2025 billing change and the 251 ms to 351 ms example
AWS Compute Blog, Operating Lambda: Performance optimization, Part 1: the under-1% figure, concurrent cold starts, and why warming pings fall short
AWS Compute Blog, Understanding and remediating cold starts: an AWS Lambda perspective: package size, memory and CPU, SnapStart, Provisioned Concurrency
AWS, AWS Lambda pricing: requests, duration, free tier, worked examples
AWS Docs, Configure Lambda function memory: memory, CPU, Power Tuning
AWS Compute Blog, AWS Lambda introduces tiered pricing for Amazon CloudWatch Logs and additional logging destinations
Comments0
Log in to join the discussion.
No comments yet.