feat(idempotency): add automatic priming for DynamoDB persistence store#2376
feat(idempotency): add automatic priming for DynamoDB persistence store#2376dcabib wants to merge 3 commits intoaws-powertools:mainfrom
Conversation
Implements automatic class preloading via CRaC hooks for the idempotency-dynamodb module to improve SnapStart cold start performance. Changes: - Add ClassPreLoader.preloadClasses() call to DynamoDBPersistenceStore.beforeCheckpoint() - Generate and include classesloaded.txt with 8,726 classes - Add powertools-common dependency for ClassPreLoader - Add Maven profile generate-classesloaded-file - Add unit tests for CRaC hooks - Update Priming.md with idempotency-dynamodb example - Add null check and logging for defensive error handling This combines both invoke priming (warming DynamoDB SDK paths) and automatic priming (preloading classes) for optimal performance. Follows the same pattern as implemented in powertools-metrics (aws-powertools#1861), powertools-tracing (aws-powertools#2345), and powertools-kafka (aws-powertools#2145). Fixes aws-powertools#1997 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| // This is unexpected but we must continue without any interruption | ||
|
|
||
| // Automatic priming - preload classes from classesloaded.txt | ||
| ClassPreLoader.preloadClasses(); |
There was a problem hiding this comment.
I think it would be better to move the preloading of classes as the first statement in this block in case the invoke priming fails we will still have pre-loaded the classes.
Per review feedback from @phipag: ensures class preloading completes even if DynamoDB invoke priming operations fail.
|
Done! 👍 |
|
Thanks @dcabib! I noticed the GraalVM native tests fail now: https://github.com/aws-powertools/powertools-lambda-java/actions/runs/21632501577/job/62352262341?pr=2376. This is because we are now using mockito to mock the CRaC context. similar to the other PRs, for example the metrics one you need to set the mockito-subclass mock maker in pom.xml. THis is the only mock maker compatible with GraalVM native tests. |
- Add mockito-subclass dependency to idempotency-dynamodb module in both generate-graalvm-files and graalvm-native profiles - Update CRaC priming tests to pass null context instead of mocking to avoid GraalVM reflection configuration requirements
|
Done! 👍 (hope it's ok right now) |
|



Description
Implements automatic class preloading via CRaC hooks for the
powertools-idempotency-dynamodbmodule to improve SnapStart cold start performance.This PR adds automatic priming support to complement the existing invoke priming that was implemented in #1861.
Changes
ClassPreLoader.preloadClasses()call toDynamoDBPersistenceStore.beforeCheckpoint()classesloaded.txtwith 8,726 classespowertools-commondependency forClassPreLoadergenerate-classesloaded-filefor regenerating the classes filebeforeCheckpoint()andafterRestore())Priming.mdwith idempotency-dynamodb exampleImplementation Details
This implementation combines both priming strategies:
classesloaded.txtduring SnapStart checkpointThe combined approach ensures optimal cold start performance by:
Pattern Consistency
Follows the same pattern as implemented in:
Key differences justified for persistence layer:
Testing
testBeforeCheckpointDoesNotThrowException()andtestAfterRestoreDoesNotThrowException()Verification
To verify this works with SnapStart:
Related Issues
Fixes #1997
Maintainer Confirmation
As confirmed by @phipag in #1997 (comment):
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.