Does DynamoDB TTL work on pre-existing items?

Viewed 1846

I have a DynamoDB table with a bunch of items in it. I had configured the table to use the attribute "expiration" as the TTL attribute. I then introduced a bug in my system where I saved all of the items with an attribute of "expiry" (doh!).

To solve this, I turned off TTL support on the table, then re-enabled it using the attribute "expiry". There should have been an earth-shattering kaboom as all of the expired items went away. There wasn't. I waited 24 hours, just in case Dynamo needed to wake up and pay attention to my table. No earth-shattering kaboom (sad martian...).

I'm now wondering if items in the table that were in place prior to enabling TTL on the correct attribute actually miss the TTL boat and will remain there until manually deleted. Did I miss something? Has anyone else experienced this?

1 Answers

Yes, DynamoDB should delete expired items even if they were created before the TTL column was chosen. At least, nothing in the documentation suggests otherwise. documentation explains how TTL works:

DynamoDB compares the current time, in epoch time format, to the value stored in the user-defined Number attribute of an item. If the attribute’s value is in the epoch time format, is less than the current time, and is not older than 5 years, the item is deleted. Processing takes place automatically, in the background.

You said that you waited for 24 hours for the deletion to happen. Maybe this wasn't enough, because the same document also says:

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.

Now that 48 hours have passed, can you please check again?

Update (based on the discussion above): If the TTL feature appears not to be working for, you should make sure that you are setting the TTL attribute correctly. First make sure you are setting the attribute with the correct name (this was the questioner's first problem). Then, you should make sure to set an integer values in this attribute (it can't be a string!). Finally make sure that this integer is the number of seconds since the epoch (midnight GMT, Jan 1, 1970) - the questioner accidentally used milliseconds instead of seconds here, so it didn't work.

Related