Support Time To Live attributes in the DynamoDB Enhanced Client
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
_[Edit by @debora-ito]_:
This changed to a feature request to add an annotation to manage DynamoDB TTL attributes in the DDB Enhanced Client.
Community note: add a 👍 to this if you are interested.
While this is not supported out of the box by the SDK, note that you can write a custom extension with the logic you need to create a TTL timestamp attribute - you can find an example in our Developer guide: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/ddb-en-client-extensions.html#ddb-en-client-extensions-custom
Original issue description below:
---
### Describe the bug
DynamoDbAutoGeneratedTimestampAttribute format in DynamoDb is incompatible with Time To Live.
When using attributes such as `createdAt` or `upatedAt` like the following:
```java
@DynamoDbAutoGeneratedTimestampAttribute
@DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
public Instant getCreatedAt() {
return createdAt;
}
@DynamoDbAutoGeneratedTimestampAttribute
public Instant getUpdatedAt() {
return updatedAt;
}
```
The value in DynamoDb is stored with the following format: `2023-06-06T18:16:40.632760903Z`.
---
This format is not compatible with a Time To Live attribute as documented here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-before-you-start.html
> The TTL attribute’s value must be a timestamp in [Unix epoch time format](https://en.wikipedia.org/wiki/Unix_time) in seconds. If you use any other format, the TTL processes ignore the item. For example, if you set the value of the attribute to 1645119622, that is Thursday, February 17, 2022 17:40:22 (GMT), the item will be expired after that time. For help formatting your epoch timestamps, you can use third-party tools such as [Epoch Converter](https://epochconverter.com/) to get a visual web form.
### Expected Behavior
I would expect that properties that specifically use the `DynamoDbAutoGeneratedTimestampAttribute` annotation would be compatible with TTL format.
### Current Behavior
And as per the general usage and documented in the project (see https://github.com/search?q=repo%3Aaws%2Faws-sdk-java-v2%20DynamoDbAutoGeneratedTimestampAttribute&type=code) we are using an `Instant`.
If this is not compatible with the TTL format on purpose, how can I store these timestamp as TTL compatible attributes?
### Reproduction Steps
```java
@DynamoDbAutoGeneratedTimestampAttribute
@DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
public Instant getCreatedAt() {
return createdAt;
}
@DynamoDbAutoGeneratedTimestampAttribute
public Instant getUpdatedAt() {
return updatedAt;
}
```
And save something to DynamoDb, check the format is not unix timestamp.
### Possible Solution
_No response_
### Additional Information/Context
I would like to not change the property type from Instant to int or something else.
### AWS Java SDK version used
2.20.30
### JDK version used
18.0.2
### Operating System and version
MacOS M1 (13.3.1)
Contributor guide
Assessment
This issue has not been assessed yet.