1.3.7 Manage Data Lifecycles
Manage Data Lifecycles
DynamoDB TTL (Time to Live)
- Tự động xóa expired items (background process)
- Attribute chứa expiration timestamp (epoch seconds)
- Không tốn WCU — xóa bởi background process
- Deleted items xuất hiện trong DynamoDB Streams (eventName =
REMOVE) - Xóa thực tế có thể delay đến 48h sau expiration
import time
# Set TTL: expire sau 7 ngày
item = {
'id': 'session-123',
'data': 'session_data',
'ttl': int(time.time()) + (7 * 24 * 60 * 60) # epoch seconds
}
table.put_item(Item=item)
S3 Lifecycle Rules
Transition Actions
S3 Standard → (30 days) → S3 Standard-IA → (60 days) → S3 Glacier
→ (90 days) → S3 Glacier Deep Archive
| Storage Class | Min Duration | Retrieval |
|---|
| Standard | — | Instant |
| Standard-IA | 30 days | Instant |
| One Zone-IA | 30 days | Instant |
| Glacier Instant | 90 days | Milliseconds |
| Glacier Flexible | 90 days | 1 min → 12 hours |
| Glacier Deep Archive | 180 days | 12 → 48 hours |
Expiration Actions
- Tự động xóa objects sau X ngày
- Xóa incomplete multipart uploads
- Xóa previous versions (versioned buckets)
S3 Versioning + Lifecycle
Current version → Transition to Glacier after 90 days
Previous versions → Delete after 30 days
Delete markers → Clean up expired delete markers
Backup & Recovery
| Service | Backup Method |
|---|
| DynamoDB | On-demand backup, Point-in-time Recovery (PITR) |
| RDS/Aurora | Automated snapshots, manual snapshots |
| S3 | Versioning, Cross-Region Replication |
- DynamoDB PITR: Restore to any second trong 35 ngày gần nhất
Exam Tip: DynamoDB TTL = free deletion (no WCU). S3 Lifecycle = auto transition/expiration. PITR cho DynamoDB = continuous backup 35 days. TTL attribute phải là epoch seconds (Number type).