What this thread does
Read the function's REPORT records first, then change the setting responsible for initialization or handler time.
Do first: separate initialization from execution
As of November 2026, these examples use AWS CLI v2 and the managed runtimes named below. In the function's CloudWatch log group, run this Logs Insights query over a representative traffic window:
filter @type = "REPORT"
| fields @timestamp, @message
| sort @timestamp desc
| limit 100
Compare Init Duration, Duration, Billed Duration, Memory Size and Max Memory Used: is initialization the slow part, or are warm requests also slow? Duration describes handler execution; initialization has its own field. Use the official REPORT field definitions. For an already enabled SnapStart function, use Restore Duration; its initialization appears in INIT_REPORT, not the invocation's REPORT. SnapStart monitoring
Choose the matching branch
1. Warm execution is slow or memory is tight → compare memory
Follow Configure function memory. CPU allocation rises with memory, so low Max Memory Used alone does not prove the memory allocation is economical. In a disposable copy of the function, compare the current allocation with 1024 MB:
aws lambda update-function-configuration --function-name my-function --memory-size 1024
Replay the same safe event mix at both allocations and hold runtime, architecture and traffic constant. Wait for the update to complete before replaying. Compare warm latency separately from cold latency. For the same region and architecture, compare allocated GB × billed seconds per completed request, plus errors; a faster invocation can still cost more. Pricing If warm time barely changes, time downstream calls before buying more CPU. AWS's memory guide also links Power Tuning for a wider sweep; it invokes real code and services.
2. Initialization dominates → change the package for that runtime
Keep the runtime version fixed while making one packaging change:
| Runtime pin | Official path → concrete change | Check in your project |
|---|---|---|
| Node.js 22 | Node.js ZIP packaging recommends bundling with esbuild or rollup to reduce dependency I/O. Bundle the actual handler and its required dependencies. | Invoke every handler path after deployment; compare artifact bytes and cold Init Duration. |
| Python 3.12 | Python ZIP packaging: remove unused dependencies and __pycache__; native wheels must match Linux and the function architecture. | Exercise native imports in Lambda, then compare initialization with the same event. A smaller ZIP that fails imports is no improvement. |
| Java 21 | Java ZIP/JAR packaging: inspect the Maven dependency set, remove unused libraries, then rebuild with mvn package. | Invoke serialization and framework paths, then compare initialization and first response latency. |
| .NET 8 | The .NET Lambda CLI guide: use <PublishReadyToRun>true</PublishReadyToRun> in the project; include shared assemblies at compile time instead of manually loading them from layers. | Rebuild and invoke the deployed handler; compare cold initialization and package size. |
Use cold samples from fresh execution environments and warm samples separately; repeated sequential calls often measure reuse. Packaging changes do not promise a fixed percentage saving.
3. Bursty traffic and long initialization → evaluate SnapStart
Java 21, Python 3.12 and .NET 8 are within the supported SnapStart runtime families; Node.js 22 is outside those families. Follow Activate SnapStart:
aws lambda update-function-configuration --function-name my-function --snap-start ApplyOn=PublishedVersions
aws lambda wait function-updated-v2 --function-name my-function
aws lambda publish-version --function-name my-function
The waiter must succeed before publishing. Use the returned version number. Run aws lambda get-function-configuration --function-name my-function:1, replacing 1 with that version. Require State: Active and SnapStart.OptimizationStatus: On, then direct the caller to that version or an alias pointing to it. Calling $LATEST bypasses this change. Compare Restore Duration plus handler duration and caller latency under a burst. Activation and checks
Before adopting it, check restored uniqueness, refresh temporary data and reconnect stale connections. Java managed runtimes have no additional SnapStart fee; Python and .NET add snapshot caching and restoration charges, with a three-hour minimum cache charge. Include those in the cost comparison. Compatibility and pricing
4. A strict latency target still fails → provision capacity
Use provisioned concurrency on a published version or alias, as an alternative to SnapStart. For an existing BLUE alias, a small comparison allocation is:
aws lambda put-provisioned-concurrency-config --function-name my-function --qualifier BLUE --provisioned-concurrent-executions 2
aws lambda get-provisioned-concurrency-config --function-name my-function --qualifier BLUE
Wait for Status: READY in the configuration response, and point the event source at BLUE. Compare caller tail latency within that capacity, then above it; spillover can use on-demand environments. Include idle provisioned capacity in total cost. Reserved concurrency alone does not pre-initialize environments, and SnapStart cannot share this configuration. Concurrency behavior
Evidence and limits
AWS's 2025-04-29 billing announcement, by Shubham Gupta and Jeff Gebhart, includes managed-runtime ZIP initialization in billed duration from 2025-08-01. Older examples that exclude it understate today's cost. The 2024-11-18 release notice dates Python 3.12/.NET 8 SnapStart support.
Independent evidence: lambdabench.dev's 2026-10-14 run separates cold and warm samples and warns that cold samples are too few for stable p99 estimates. Its measurement definition excludes download and environment setup from REPORT-based cold time. Measure caller latency too; benchmark results are workload-specific.
After invocation failures, a suppressed initialization can be folded into duration without a separate init field; inspect failures before classifying those requests as ordinary warm calls. Execution lifecycle
Not for: Cloudflare Workers platform selection; see cloudflare-workers-or-aws-lambda-for-a-spiky-api.
Started from a post by @Shubham Gupta and Jeff Gebhart, packaged by the editor. Original post