Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB time to live per Item

I have a requirement to expire items with different time to live configuration. There are cases where items in table won't expire of certain cases as well. In Cassandra we can set time-to-live while writing at the record level. In DynamoDB I could only see the TimeToLive configuration at table level (I could be wrong too.) but not at item level.

  1. Is there a way to set TTL at item level while doing putItem or
  2. What are the best practices to delete records with minimal effect on the overall system?

If there is no possibility to set TTL at item level, i would like to fall back to second option.

like image 471
Srini Avatar asked Apr 23 '19 02:04

Srini


People also ask

How do I add TTL to DynamoDB table?

Sign in to the AWS Management Console and open the DynamoDB console at https://console.aws.amazon.com/dynamodb/ . Choose Tables, and then choose the table that you want to modify. In the Additional settings tab, in the Time to Live (TTL) section, choose Enable.

How accurate is DynamoDB TTL?

Yes according to the link you sent. DynamoDB typically deletes expired items within 48 hours of expiration. The exact duration within which an item truly gets deleted after expiration is specific to the nature of the workload and the size of the table.

Can you update TTL in DynamoDB?

The key statement, as you pointed out, is at How It Works: DynamoDB Time to Live (TTL): Items that are past their expiration, but have not yet been deleted can still be updated, and successful updates to change or remove the expiration attribute will be honored.


1 Answers

DynamoDB can absolutely do this on the item level in the table. In the table level configurations is where you tell DynamoDB the name of the attribute that will contain the value for the TTL. This attribute name can be whatever you want. Then on each item you write to the table, you include an attribute named what you told DynamoDB to look for with the value in epoch time format in seconds. Once you do that, when that item's time comes, DynamoDB will lazy delete the item in 24-48 hours. Best of all, that delete is of no cost to you.

For more information on how to enable TTL go here. For more about how TTL works, go here.

like image 198
Kirk Avatar answered Oct 18 '22 10:10

Kirk