Cut Java Lambda cold starts with SnapStart and move non-deterministic code into handlers

Answer Correct answer: D — Add a pre-snapshot hook, move unique ID generation into the handlers, publish versions, and activate SnapStart on those versions.

A company is developing a latency-sensitive application. Part of the application includes several AWS Lambda functions that need to initialize as quickly as possible. The Lambda functions are written in Java and contain initialization code outside the handlers to load libraries, initialize classes, and generate unique IDs. Which solution will meet the startup performance requirement MOST cost-effectively?

  1. Move all the initialization code to the handlers for each Lambda function. Activate Lambda SnapStart for each Lambda function. Configure SnapStart to reference the $LATEST version of each Lambda function.
  2. Publish a version of each Lambda function. Create an alias for each Lambda function. Configure each alias to point to its corresponding version. Set up a provisioned concurrency configuration for each Lambda function to point to the corresponding alias.
  3. Publish a version of each Lambda function. Set up a provisioned concurrency configuration for each Lambda function to point to the corresponding version. Activate Lambda SnapStar for the published versions of the Lambda functions.
  4. Update the Lambda functions to add a pre-snapshot hook. Move the code that generates unique IDs into the handlers. Publish a version of each Lambda function. Activate Lambda SnapStart for the published versions of the Lambda functions. Correct Answer

Community Votes

D
76%
C
24%

76% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

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.

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.

Community Discussion (11 comments)

Russs99 👍 5 Selected: D
While option B improves startup performance, it is generally more expensive than SnapStart because it keeps environments warm continuously.
AzureDP900 👍 1
Option 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.
JoeTromundo 👍 2 Selected: D
For 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
zolthar_z 👍 2 Selected: D
https://aws.amazon.com/blogs/compute/reducing-java-cold-starts-on-aws-lambda-functions-with-snapstart/
backbencher2022 👍 1 Selected: D
D 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
dzidis 👍 3 Selected: D
You 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
vip2 👍 3 Selected: D
D 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.
5ehjry6sktukliyliuliykutjhy 👍 1 Selected: C
It is C
[Removed] 👍 1 Selected: C
Provisioned 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.
mifune 👍 2 Selected: C
"Lambda SnapStart for Java can improve startup performance for latency-sensitive applications by up to 10x at no extra cost". Answer C.
ebbff63 👍 1 Selected: C
Leverages both versioning and provisioned concurrency. Also Lambda SnapStart for improved startup performance.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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

Related Analysis

Practice All SAP-C02 Questions

Access 85 questions with complete answers and detailed explanations.

View Full SAP-C02 Practice Test →

← Back to SAP-C02 Study Guide