Cut Java Lambda cold starts with SnapStart and move non-deterministic code into handlers
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?
Community Votes
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)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
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 →