Cut Java Lambda cold starts with SnapStart and move non-deterministic code into handlers
Short answer
D Add a pre-snapshot hook, move unique ID generation into the handlers, publish versions, and activate SnapStart on those versions.
Question
Key Takeaways
SnapStart snapshots a fully initialized execution environment during publishing and restores it on the next invocation, so the cost is only paid at publish time, but it cannot be used on a version that also has provisioned concurrency, and any code that must differ per invocation has to move into the handler.
Several Java Lambda functions do initialization work outside the handler, including loading libraries, initializing classes, and generating unique IDs, and they must start as fast as possible at the lowest cost. SnapStart is the AWS feature designed to reduce Java initialization time.
Common mistake: Combining SnapStart with provisioned concurrency on the same published version. The AWS documentation states SnapStart does not support provisioned concurrency, so option C cannot work, and reaching for provisioned concurrency alone is the more expensive answer to a most cost-effective question.
Expert Analysis
Why the Answer Is Correct
Publishing a version and activating SnapStart for it lets Lambda create the snapshot once at publish time and restore that memory image on subsequent cold starts, which removes the library loading and class initialization cost and is cheaper than keeping environments warm. Because a snapshot captures a single frozen memory state, code that generates a unique ID per invocation would be frozen into the snapshot and repeat the same value, so that code is moved into the handler. The pre-snapshot hook is where the deterministic initialization work belongs, which is exactly what the option describes.
Why the Other Options Are Wrong
A: SnapStart cannot be applied to the $LATEST version, it must be activated on a published version, and moving all initialization into the handler undoes the benefit because the work then runs on every cold start. B and C: Provisioned concurrency keeps environments warm continuously, which is the more expensive approach and does not meet the most cost-effective requirement, and the AWS documentation states that SnapStart does not support provisioned concurrency for the same function version, which is why option C cannot work as written.
Community Comment Notes
The community voted 76 to 24 for D over C. The decisive evidence was a link to the SnapStart documentation noting that SnapStart does not support provisioned concurrency, which invalidates option C, and commenters noted that option B works but keeps environments warm at higher ongoing cost.
Official Reference
https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
This link opens the official vendor documentation in a new tab.
Community Votes
76% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 11 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 11
-
Russs99 👍 5 Answered DWhile option B improves startup performance, it is generally more expensive than SnapStart because it keeps environments warm continuously.
-
vip2 👍 3 Answered DD Combining provisioned concurrency with SnapStart is redundant While provisioned concurrency reduces cold start latency, it is more costly compared to SnapStart because it keeps a set number of instances warm and ready to handle requests, even when not in use.
-
dzidis 👍 3 Answered DYou can't use both SnapStart and provisioned concurrency on the same function version. Therefore cannot be C. https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
-
JoeTromundo 👍 2 Answered DFor those who think option C is correct: as dzidis commented, "SnapStart does NOT support PROVISIONED CONCURRENCY" https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html
-
mifune 👍 2 Answered C"Lambda SnapStart for Java can improve startup performance for latency-sensitive applications by up to 10x at no extra cost". Answer C.
Show 6 more comments
-
zolthar_z 👍 2 Answered Dhttps://aws.amazon.com/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/
-
AzureDP900 👍 1Option D is right This solution provides a good balance between performance and code organization. By moving the code that generates unique IDs into the handlers, you keep the initialization code out of the way, but still make it accessible when needed. The pre-snapshot hook allows you to run some initialization code before the Lambda function is executed, which can be useful for tasks like generating unique IDs. Publishing a version of each Lambda function and activating SnapStart ensures that the functions are running with the latest code and optimizations.
-
[Removed] 👍 1 Answered CProvisioned concurrency – This is the number of pre-initialized execution environments allocated to your function. These execution environments are ready to respond immediately to incoming function requests. Provisioned concurrency is useful for reducing cold start latencies for functions. Configuring provisioned concurrency incurs additional charges to your AWS account.
-
backbencher2022 👍 1 Answered DD is correct and as dzidis referred to AWS document, you can't use both provisioned concurrency and SnapStart for the same function version. Therefore, C can't be a correct option. Refer to this section of document for more details: https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html#snapstart-concurrency
-
ebbff63 👍 1 Answered CLeverages both versioning and provisioned concurrency. Also Lambda SnapStart for improved startup performance.
-
5ehjry6sktukliyliuliykutjhy 👍 1 Answered CIt is C
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All SAP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full SAP-C02 Practice Test →