Time To Live (TTL)

Section preview

A feature that allows you to automatically delete items from a table. TTL requires an attribute to be specified as the timestamp (or TTL) attribute. This attribute is monitored by DynamoDB for expiry (i.e., deletion) of item.

  • Requires enabling on the table
  • Application can Put items with or without timestamp (or TTL) attribute
  • DynamoDB automagically expires (deletes) the item sometime after the time specified in the timestamp attribute
  • If stream is enabled then a stream record is written to the stream
  • A metric TimeToLiveDeletedItemCount is managed in CloudWatch

how-it-works

TTL Attribute

  • Value in attribute is in UNIX Epoch format
  • TTL attribute MUST be top-level
  • TTL attribute MUST be of Number type
  • If the value in TTL attribute is not a Number then item is not expired
  • No action taken on items that do not have the TTL attribute
  • Expiry time from past cannot be older than 5 years; item will not be expired

Item expiry

The deletion of item happens some time after the expiry of the TTL.

Deletion may take hours and even days !!!

  • Feature is free to use; write capacity is NOT used for item expiry
  • If stream is enabled then an event is written to the stream
  • Global Table TTL is NOT free

Setting up TTL on table

It is not enabled by default. You need to update the table and specify an attribute as the TTL attribute.

TTL enabling/disabling may take up to 1 hour for the settings to propagate and to allow the execution of any further TTL related actions

References

AWS Documentation

Online Epoch Converter

TTL CloudWatch Metric