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 ClassMin DurationRetrieval
StandardInstant
Standard-IA30 daysInstant
One Zone-IA30 daysInstant
Glacier Instant90 daysMilliseconds
Glacier Flexible90 days1 min → 12 hours
Glacier Deep Archive180 days12 → 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

ServiceBackup Method
DynamoDBOn-demand backup, Point-in-time Recovery (PITR)
RDS/AuroraAutomated snapshots, manual snapshots
S3Versioning, 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).