🟢
DynamoDB – Time To Live (TTL)
- Automatically removes items from a table when a designated expiration timestamp is reached.
- Helps control storage costs and manage data lifecycle without manual cleanup jobs.
How It Works
- You enable TTL on a specific attribute in the table (e.g.,
ExpTime
).
- Value must be a UNIX epoch timestamp (in seconds).
- When the current time passes this value, DynamoDB marks the item as expired.
- Deletion happens in the background, usually within 48 hours (best-effort, not guaranteed immediate).
Use Cases
- Session management (auto-expire inactive sessions)
- Event logs with a retention period
- Regulatory compliance (automatic deletion after retention window)
Important Notes
- Expired items are not returned in queries or scans once deleted.
- TTL deletes are free and do not consume write capacity.
- Deleted items can still appear in DynamoDB Streams before removal.