Why aren't the items with expired Time to Live deleted from my Amazon DynamoDB table?

3 minute read

Some of the items with expired Time to Live (TTL) aren't delete from my Amazon DynamoDB table.


The DynamoDB TTL feature allows you to define a per-item timestamp to determine when you no longer need an item. Shortly after the date and time of the specified timestamp, DynamoDB deletes the item from your table. This doesn't consume any write throughput. TTL allows you to retain only the items that remain current for your workload's needs and therefore reduce stored data volumes. TTL doesn't incur any additional costs. When you activate TTL on a DynamoDB table, identify an attribute name for the service to look for to determine an item's eligibility for expiration. After you activate TTL on a table, a per-partition scanner background process automatically and continuously evaluates the expiry status of items in the table.

Here are some common reasons why the deletion of expired items might take longer than expected:

  • The actual delete operation of an expired item might vary depending on the size and activity level of your table. Because TTL is a background process, the capacity that it uses to expire and delete items can vary.
  • TTL typically deletes expired items within a few days. Depending on the size and activity level of a table, the actual delete operation of an expired item can vary. TTL deletes items on a best effort basis, and deletion might take longer in some cases. During the deletion of objects, DynamoDB uses the backend capacity of the table to delete the objects instead of the provisioned capacity. If there are many delete requests and not enough backend capacity to continuously delete those items, then the process might take longer.

To check if TTL is working properly, verify the following conditions:

  • Be sure that you activated TTL on the table and the related settings are correct:

  • The item must contain the attribute that you specified when you activated TTL on the table.

  • The TTL attribute's value must have the data type Number.

  • The TTL attribute's value must be a timestamp in seconds in Unix epoch time format. For more information, see Unix time on Wikipedia.

  • The TTL attribute value must be a datetimestamp with an expiration of no more than five years in the past.

  • The TTL processes run on the table only when there's enough spare capacity so that these processes don't interfere with table operations. If the table or table partitions use most of the allocated capacity, then TTL processes might not run.

Items that expired but aren't yet deleted still appear in reads, queries, and scans. If you don't want expired items in the result set, then you must filter them out. Use a filter expression that returns only items where the Time to Live expiration value is greater than the current time in epoch format. For more information, see Filter expressions for scan.

Related information

Expiring items by using DynamoDB Time to Live (TTL)

AWS OFFICIALUpdated 7 months ago