Why are the items with expired Time to Live not deleted from my Amazon DynamoDB table?
Last updated: 2022-08-26
Some of the items with expired Time to Live (TTL) aren't yet deleted from my Amazon DynamoDB table.
The DynamoDB TTL feature allows you to define a per-item timestamp to determine when an item is no longer needed. Shortly after the date and time of the specified timestamp, DynamoDB deletes the item from your table without consuming any write throughput. TTL is provided at no extra cost as a means to reduce stored data volumes by retaining only the items that remain current for your workload’s needs. When you activate TTL on a DynamoDB table, you must identify a specific attribute name that the service will look for when determining if an item is eligible 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.
Some of the common causes for deletion of expired items taking longer are the following:
- 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 nature of the capacity used to expire and delete items using TTL is variable.
- The TTL process typically deletes expired items within 48 hours of expiration. However, this timeline isn't an SLA. TTL deletes are done on best effort basis and deletion might take longer in some cases. During the deletion of objects using TTL, DynamoDB uses the backend capacity of the table to delete the objects instead of using the provisioned capacity. The deletion process might take longer if there are a large number of delete requests and not enough backend capacity to continuously delete those items.
To check if TTL is working properly, do the following:
- 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 datatype Number.
- The TTL attribute’s value must be a timestamp in Unix epoch time format in seconds.
- 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 is enough spare capacity so that these processes don't interfere with table operations. If the table or table partitions are using most of the allocated capacity, TTL processes might not run due to insufficient spare capacity.
Items that are expired, but aren't yet deleted by TTL, still appear in reads, queries, and scans. If you don't want expired items in the result set, you must filter them out. To do so, 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.