Serverless Cold Starts: Measuring and Fixing Them on Lambda
A p99 that jumps past three seconds during traffic ramps is often cold starts. Here's how to measure them properly and cut the tail.
Key takeaways
- Measure Lambda cold starts with the Init Duration field on REPORT log lines, which only appears on cold invocations.
- Shrink the deployment bundle first, since it is free and speeds every init.
- Then add provisioned concurrency on a schedule for predictable ramps, or SnapStart for Java, Python and .NET functions with spiky traffic.
On this page
Find Lambda cold starts by querying @initDuration on REPORT log lines in CloudWatch Logs Insights; only cold invocations carry it. Fix them in cost order: shrink the bundle (free, helps every init), schedule provisioned concurrency for predictable ramps, and use SnapStart on Java, Python or .NET when traffic is spiky. Skip the ping-based warmers.
Verified againstChecked against official docs
Lambda managed runtimes nodejs24.x and java21, against the AWS Lambda developer guide pages for SnapStart, provisioned concurrency and runtimes, and the Lambda pricing page (us-east-1 rates). Checked October 2026.
A product manager pinged me at 9am: "the app feels slow first thing in the morning." Our average latency looked fine. But the p99 on our order API told a different story. It spiked past three seconds every day right as European traffic woke up, then settled back under 200ms by mid-morning. Classic cold start signature: pain concentrated at the start of a traffic ramp, invisible in the average.
Measure the init phase, not just total duration
Total invocation time hides the split between "cold" and "warm." Lambda already logs the init duration; you just have to go pull it. The REPORT line in CloudWatch has an Init Duration field, but only on cold invocations. Query it directly with Logs Insights:
filter @type = "REPORT"
| fields @initDuration
| stats count(@initDuration) as coldStarts,
avg(@initDuration) as avgInit,
pct(@initDuration, 99) as p99Init
by bin(1h)
Binning by hour is what made the morning pattern obvious for us: a couple of thousand cold starts a day, bunched into the first hour of the ramp, with average init close to two seconds. That init time is pure overhead the user pays before your code runs a single line. Ours was mostly the Node.js runtime loading a deployment bundle of a couple hundred megabytes and initializing an AWS SDK client tree plus a database connection.
If you use provisioned concurrency, its init happens at allocation time and is reported in a platform-initReport event (JSON log format, level INFO or higher) rather than on the request path, so do not expect it in the same query.
The package size tax is real
We ran du on the unzipped bundle and found the whole AWS SDK v2 shipped in, plus dev dependencies that slipped past the build. Two fixes:
Move to the modular AWS SDK v3 and import only what you call.
// before: pulls the whole SDK
const AWS = require('aws-sdk');
// after: just the DynamoDB client
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
Then bundle with esbuild and tree-shake, so only reachable code ships:
npx esbuild src/handler.js --bundle --minify --platform=node \
--target=node24 --outfile=dist/handler.js
We bundle the SDK client rather than marking @aws-sdk/* external. The Node.js runtime does include an SDK v3 build, but AWS's runtime docs recommend packaging the SDK modules your code uses so automatic runtime updates cannot change them under you. Target node24 and deploy on nodejs24.x: nodejs20.x was deprecated on April 30, 2026. Python and .NET run on the same clock: python3.10 was deprecated October 31 and dotnet8 support ends November 10.
The bundle dropped from hundreds of megabytes to around ten, and init roughly halved. Package size is the cheapest lever and most teams ignore it. If you are setting a function up from scratch, our walkthrough on deploying your first Lambda function starts with this bundling step.
Provisioned concurrency for the predictable ramp
Package cuts help every invocation but won't get you to zero cold starts. For the morning ramp, we knew roughly how many concurrent executions we'd need, so we bought provisioned concurrency and scheduled it instead of leaving it on 24/7 (that's the expensive mistake).
resource "aws_lambda_provisioned_concurrency_config" "order_api" {
function_name = aws_lambda_function.order_api.function_name
qualifier = aws_lambda_alias.live.name
provisioned_concurrent_executions = 20
}
resource "aws_appautoscaling_scheduled_action" "morning_ramp" {
name = "warm-before-eu-traffic"
resource_id = "function:order_api:live"
scalable_dimension = "lambda:function:ProvisionedConcurrency"
service_namespace = "lambda"
schedule = "cron(45 5 * * ? *)" # 05:45 UTC, before the ramp
scalable_target_action {
min_capacity = 20
max_capacity = 20
}
}
The schedule needs a registered scalable target for the alias and a matching evening action that drops capacity back to 2. AWS's docs also say to set an initial provisioned concurrency value before handing it to Application Auto Scaling, and to point event sources at the alias, not $LATEST, or the warm environments are never used.
The money is in the schedule. As of October 2026, us-east-1 bills provisioned concurrency at $0.0000041667 per GB-second, whether or not it serves traffic. At 1,024 MB, 20 units around the clock come to roughly $219 a month before duration charges. Twenty units for a four-hour morning window and 2 units the rest of the day come to roughly $54. Same p99 during the ramp, a quarter of the bill.
SnapStart if you're on the JVM
For our one Java Lambda, provisioned concurrency felt wasteful for spiky traffic. SnapStart was the better fit: it snapshots the initialized execution environment when you publish a version and resumes new environments from that snapshot, so the JVM warmup cost is paid once at publish, not per cold start.
# template.yaml (AWS SAM, under the function's Properties)
SnapStart:
ApplyOn: PublishedVersions
It took our Java cold start from several seconds to well under one, which matches what AWS's docs promise ("from several seconds to as low as sub-second"). For Java managed runtimes there is no extra charge. SnapStart now also covers Python 3.12+ and .NET 8+, but those runtimes pay snapshot caching and restore fees. It does not support Node.js, provisioned concurrency, EFS, or ephemeral storage above 512 MB.
The catch: anything you create during init (a random seed, a unique ID, a connection) gets frozen into the snapshot and reused across environments. We had to move connection setup out of init and into the handler, and add a runtime hook to reseed randomness.
Don't over-engineer the warm path
One thing we tried and abandoned: a "warmer" CloudWatch rule pinging the function every 5 minutes to keep it alive. It kept exactly one environment warm, which does nothing for a ramp that needs twenty at once, and it muddied our invocation metrics. Provisioned concurrency solves the same problem correctly. Ditch the ping trick.
Where we ended up
Init time roughly halved via bundle cuts, the morning p99 back in line with the rest of the day via scheduled provisioned concurrency, and the Java service fixed with SnapStart. The PM stopped pinging me at 9am. Kubernetes teams hit the same ramp problem with slow-starting pods, and GKE pod snapshots are that platform's version of SnapStart.
Questions people ask
How do I see Lambda cold starts in CloudWatch?
Run a Logs Insights query on the function's log group filtering @type = "REPORT" and aggregating @initDuration. Only cold invocations log an Init Duration, so count(@initDuration) is your cold start count and pct(@initDuration, 99) is the tail. Bin by hour to see whether cold starts cluster around traffic ramps or deploys. X-Ray traces show the same init segment per request.
Is provisioned concurrency worth the cost?
Only for predictable, latency-sensitive traffic. You pay for every allocated unit per GB-second, used or idle, so a flat 24/7 setting is the expensive version. Schedule it with Application Auto Scaling around known ramps, or use target tracking on LambdaProvisionedConcurrencyUtilization for steadier load. Asynchronous and batch functions rarely need it at all.
Does SnapStart work with Node.js?
No. As of October 2026, SnapStart supports Java 11 and later, Python 3.12 and later, and .NET 8 and later. Node.js and OS-only runtimes are not supported. For Node functions, the levers are a smaller bundle, lazy initialization of rarely used clients, and provisioned concurrency for the windows where cold starts actually hurt.
The call we'd make
Fix package size first; it's free and helps everything. Only then reach for provisioned concurrency, and always put it behind a schedule tied to your actual traffic shape. Leaving provisioned concurrency running flat is how serverless quietly gets as expensive as the servers you left behind.
Sources
Cite this article
Kiril Urbonas (2026). Serverless Cold Starts: Measuring and Fixing Them on Lambda. DevOpsNess. Updated 2026-11-20. https://www.devopsness.com/blog/serverless-cold-starts-measuring-and-fixing-lambda
[Serverless Cold Starts: Measuring and Fixing Them on Lambda](https://www.devopsness.com/blog/serverless-cold-starts-measuring-and-fixing-lambda) (Kiril Urbonas, DevOpsNess, updated 2026-11-20)
More from Cloud
Explore more articles in this category
Kubernetes Cost Optimization for Teams: FinOps Tactics That Actually Work
Cut Kubernetes spend without hurting reliability using a practical FinOps playbook for rightsizing, autoscaling guardrails, showback, and weekly waste cleanup.
AWS Cost Audit: 7 Places Money Leaks Every Month
A real cost audit uncovered idle load balancers, oversized RDS instances, and forgotten snapshots. Here's what we found and how we fixed each one.
Best Practices: AWS Cost Control with Tagging and Budgets
AWS bill grew 40% YoY for two years before we got serious. Tagging, scoped budgets, and a weekly review meeting did 80% of the work.
You might have missed
Evergreen posts worth revisiting.