Annotation for dynamodb enhanced client to automatically create a timestamp on for newly created object or update existing ones.
#WARNING
- The strategy ALWAYS does not work because DynamoDB extension WriteModification does not support update expressions, it only has updated values and a conditional expression
// When creating a client, you need to add the extension
private static final DynamoDbClient DYNAMO_CLIENT = DynamoDbClient.builder()
.region(Region.US_WEST_2)
.build();
private static final DynamoDbEnhancedClient CLIENT = DynamoDbEnhancedClient.builder()
.dynamoDbClient(DYNAMO_CLIENT)
.extensions(new AutoGeneratedTimestampExtension()) // Adding extension
.build();
public class Customer {
private String name;
@DynamoDbAutoGeneratedTimestampAttribute(strategy = AutoGenerateStrategy.CREATE)
private Instant joinedTimestamp;
@DynamoDbAutoGeneratedTimestampAttribute(strategy = AutoGenerateStrategy.ALWAYS)
private Instant lastUpdatedTimestamp;
}