Class AutoGeneratedUuidExtension

java.lang.Object
software.amazon.awssdk.enhanced.dynamodb.extensions.AutoGeneratedUuidExtension
All Implemented Interfaces:
DynamoDbEnhancedClientExtension

@ThreadSafe public final class AutoGeneratedUuidExtension extends Object implements DynamoDbEnhancedClientExtension
This extension facilitates the automatic generation of a unique UUID (Universally Unique Identifier) for a specified attribute every time a new record is written to the database. The generated UUID is obtained using the UUID.randomUUID() method.

This extension is not loaded by default when you instantiate a DynamoDbEnhancedClient. Therefore, you need to specify it in a custom extension when creating the enhanced client.

Example to add AutoGeneratedUuidExtension along with default extensions is

 DynamoDbEnhancedClient.builder().extensions(Stream.concat(ExtensionResolver.defaultExtensions().stream(),
 Stream.of(AutoGeneratedUuidExtension.create())).collect(Collectors.toList())).build();

Example to just add AutoGeneratedUuidExtension without default extensions is

             DynamoDbEnhancedClient.builder().extensions(AutoGeneratedUuidExtension.create()).build();

To utilize the auto-generated UUID feature, first, create a field in your model that will store the UUID for the attribute. This class field must be of type String, and you need to tag it as the autoGeneratedUuidAttribute. If you are using the BeanTableSchema, then you should use the DynamoDbAutoGeneratedUuid annotation. If you are using the StaticTableSchema, then you should use the AutoGeneratedUuidExtension.AttributeTags.autoGeneratedUuidAttribute() static attribute tag.

Every time a new record is successfully put into the database, the specified attribute will be automatically populated with a unique UUID generated using UUID.randomUUID(). If the UUID needs to be created only for `putItem` and should not be generated for an `updateItem`, then UpdateBehavior.WRITE_IF_NOT_EXISTS must be along with DynamoDbUpdateBehavior