Skip to content

DynamoDB TTL to mark the item as expired

0

Can I use DynamoDB TTL to mark a record as "expired" in a column after 24 hours instead of deleting it, and then delete it a year later?

asked a year ago346 views
3 Answers
1
Accepted Answer

No, a TTL is used to delete an item so you'd set the TTL for the (eventual, year from now) deletion time.

If an item could be marked as "expired" what would you want the behaviour to be?

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • I have a column indicating whether a record is active or not, and I need this column to automatically update to "expired" 24 hours after the record is created. I'm seeking a more efficient solution for this automatic update after 24 hours, without relying on Lambda functions and EventBridge.

  • Use logic in your code than updating the column every 24 hours? Rely on the creation timestamp. Using lambda to make updates to dynamo costs $ on read and writes. TTL deletes are free

  • Gary's comment is correct - the way I would do it is use application logic to treat a record as inactive if the TTL is set.

1

Use logic in your code not to display data older than X days and set the TTL to expire after a year

EXPERT
answered a year ago
0

In order to be able to use TTL as you suggest, you have to implement other additional mechanisms such as

  • DynamoDB Stream that allows you to get the details of the deleted item
  • Lambda as a trigger, preferably using filters for TTL deletions

So, in the Lambda, you would have to re-upload the item to DDB with the updated values ​​you need.

NOTE: Using these services may increase your bill, it might be easier to use the logic in your code

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.