-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Time To Live attributes in the DynamoDB Enhanced Client #4295
Comments
I don't think there was an intention to make |
Makes a lot of sense! |
@acouvreur just curious why you want ttl to always be equal to the current timestamp, since the item will always be deleted shortly after? In general it could be convenient to use |
Oh, you're completely right @swar8080 ! Actually I got it wrong with TTL in the first place. I thought I could configure the expiration based on a updatedAt property and somewhere I could configure TTL = 1 day But in fact the TTL property only states the date after which it should be deleted. So in my case I would have to create a new field which would be the value of updatedAt + 1 day I understand now that this feature request does not make much sense. However, I'd still need to "hook" on the updatedAt attribute being updated automatically to update my new expiresAt attribute. Do you have any recommendations on how to achieve that? |
Does it need to be hooked up on the If not, you can define a new class and write a custom AttributeConverter where it gets the current time and adds whatever logic necessary to calculate the TTL date. @swar8080 good catch, thank you. Closing this since it's not needed anymore. |
Reopening this, as we got the same request in another issue. |
I'm very interested in this, because I don't find other way to define the TTL of a table item. |
[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
orupatedAt
like the following: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
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
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)
The text was updated successfully, but these errors were encountered: