Time to Live (TTL)

Automatically delete expired items to reduce storage costs without incurring deletion charges.

What is Time to Live (TTL)?

Amazon DynamoDB’s Time to Live (TTL) feature allows you to define an expiration time for items in your tables.1 When an item’s expiration time is reached, DynamoDB automatically deletes the item, helping reduce storage costs by removing unnecessary data.

Key benefits:

  • Automatic cleanup - No manual intervention required
  • Zero deletion cost - TTL deletions are free in the source region (no WCU charges)1
  • Reduced storage costs - Only pay for data you actually need
  • Simplified architecture - No need for scheduled cleanup jobs

Note: For Global Tables, the initial TTL delete does not consume WCUs in the region where the TTL expiry occurs. However, replicated TTL deletes to replica tables consume replicated Write Capacity Units in each replica region.

Important: Once an item is deleted due to TTL, it cannot be recovered. Carefully consider your data retention requirements before enabling TTL.

How TTL works

TTL mechanics

  1. Enable TTL on your table and specify a TTL attribute name
  2. Store expiration time in Unix epoch time format (seconds granularity) in the TTL attribute
  3. DynamoDB monitors items and marks expired items for deletion
  4. Background process deletes expired items

TTL attribute format

The TTL attribute must be:

  • Number data type (not String)
  • Unix epoch time in seconds (not milliseconds)
  • At the item level (not nested in maps or lists)

Important considerations

Deletion timing

  • Not immediate - Items are deleted within a few days of expiration1
  • Typically faster - Most items deleted within hours for small tables, but can take longer for large/busy tables
  • Background process - Deletions happen asynchronously with no timing guarantees
  • No SLA - Don’t rely on exact deletion timing for business logic

Implication: Expired items may still appear in queries/scans until actually deleted. Filter expired items in your application if necessary

Real-world timing: While AWS documentation states “within a few days,” community experience suggests most deletions complete within 10-30 minutes for small tables, though large or busy tables may take hours to days. There is no official timing SLA.

DynamoDB Streams integration

TTL deletions appear in DynamoDB Streams as REMOVE events with a special flag.2

{
  "eventName": "REMOVE",
  "userIdentity": {
    "type": "Service",
    "principalId": "dynamodb.amazonaws.com"
  },
  "dynamodb": {
    "Keys": { "id": { "S": "item-123" } },
    "OldImage": { /* deleted item data */ }
  },
  "eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789012:table/MyTable/stream/...",
  "ttl": true  // Indicates this was a TTL deletion
}

Resources

Footnotes

  1. DynamoDB Time to Live 2 3

  2. DynamoDB Streams and TTL