Ngày 6: S3 và Storage Review
Mục tiêu học tập
- Ôn tập S3 storage classes và lifecycle policies
- Hiểu S3 security và encryption
- Nắm vững S3 performance optimization
1. S3 Storage Classes
So sánh Storage Classes
| Class | Availability | Durability | Min Duration | Use Case |
|---|---|---|---|---|
| Standard | 99.99% | 99.999999999% | None | Frequently accessed |
| Express One Zone | 99.95% | 99.999999999% | 1 hour | Ultra-low latency (single-digit ms), AI/ML training, request-heavy |
| Intelligent-Tiering | 99.9% | 99.999999999% | None | Unknown pattern |
| Standard-IA | 99.9% | 99.999999999% | 30 days | Infrequent access |
| One Zone-IA | 99.5% | 99.999999999% | 30 days | Non-critical, infrequent |
| Glacier Instant | 99.9% | 99.999999999% | 90 days | Archive, instant access |
| Glacier Flexible | 99.99% | 99.999999999% | 90 days | Archive, minutes-hours |
| Glacier Deep Archive | 99.99% | 99.999999999% | 180 days | Long-term archive |
S3 Express One Zone (GA Nov 2023)
Storage class hiệu năng cực cao, được thiết kế cho workload đòi hỏi truy cập với độ trễ thấp nhất.
Đặc điểm chính:
- Latency: single-digit millisecond (nhanh hơn S3 Standard 10x)
- Throughput: hàng triệu request/giây trên mỗi bucket (single-digit ms first-byte latency)
- Storage: chỉ trong một Availability Zone duy nhất (giảm latency, mất HA cross-AZ)
- Pricing: storage cost cao hơn S3 Standard ~7-8x, nhưng request cost rẻ hơn 50%
- Min storage duration: 1 giờ (so với 30 ngày của Standard-IA)
- Bucket type: Directory bucket (cấu trúc khác bucket thường, dùng cho high-performance pattern)
Use cases:
- AI/ML training data với hàng triệu small objects
- High-frequency trading, real-time analytics
- Interactive applications cần đọc/ghi tần suất cao
- Workload có data có thể tái tạo (vì single-AZ → mất AZ = mất data)
Trade-off SAP-C02 hay hỏi:
- Single-AZ → KHÔNG dùng cho mission-critical data (không có cross-AZ redundancy)
- Storage cost cao → chỉ dùng khi latency/throughput thực sự quan trọng
- Không hỗ trợ replication, versioning đầy đủ như S3 Standard
- Phải dùng Directory bucket, không phải General-purpose bucket
S3 Intelligent-Tiering
Glacier Retrieval Options
| Tier | Glacier Flexible | Deep Archive | Time |
|---|---|---|---|
| Expedited | $$ | N/A | 1-5 minutes |
| Standard | $ | $ | 3-5 hours / 12 hours |
| Bulk | ¢ | ¢ | 5-12 hours / 48 hours |
2. S3 Lifecycle Policies
Example Policy
{
"Rules": [
{
"ID": "Move to IA after 30 days",
"Status": "Enabled",
"Filter": {"Prefix": "logs/"},
"Transitions": [
{
"Days": 30,
"StorageClass": "STANDARD_IA"
},
{
"Days": 90,
"StorageClass": "GLACIER"
}
],
"Expiration": {
"Days": 365
}
}
]
}
Lifecycle Flow
3. S3 Security
Access Control Methods
Block Public Access
Account Level + Bucket Level Settings:
- BlockPublicAcls
- IgnorePublicAcls
- BlockPublicPolicy
- RestrictPublicBuckets
Best Practice: Enable all blocks unless explicitly needed
4. S3 Encryption
Encryption Types
Encryption at rest - Best Practice
Bucket Default Encryption:
{
"Rules": [{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms",
"KMSMasterKeyID": "arn:aws:kms:region:account:key/key-id"
},
"BucketKeyEnabled": true ← Giảm KMS API calls
}]
}
5. S3 Performance
Baseline Performance
- 3,500 PUT/COPY/POST/DELETE requests per second per prefix
- 5,500 GET/HEAD requests per second per prefix
Multi-Part Upload
File Size Recommendation:
< 100 MB → Single PUT
≥ 100 MB → Multi-Part Upload (recommended)
> 5 GB → Multi-Part Upload (required)
Benefits:
- Parallel uploads
- Pause and resume
- Begin upload before knowing final size
S3 Transfer Acceleration
S3 Byte-Range Fetches
6. S3 Replication
Types
| Feature | Same-Region (SRR) | Cross-Region (CRR) |
|---|---|---|
| Use Case | Log aggregation | Compliance, DR |
| Latency | Low | Higher |
| Regions | Same | Different |
Requirements
- Versioning enabled on both buckets
- IAM permissions for replication
- Objects encrypted with SSE-S3 or SSE-KMS (with proper key policy)
What's NOT replicated
- Objects before replication enabled
- Objects encrypted with SSE-C
- Delete markers (optional to replicate)
- Lifecycle rules actions
7. S3 Event Notifications
Destinations
Event Types
- s3:ObjectCreated:*
- s3:ObjectRemoved:*
- s3:ObjectRestore:*
- s3:Replication:*
8. Câu hỏi ôn tập
-
Object cần lưu trữ 30 ngày rồi chuyển Glacier, chọn class nào?
Xem đáp án
Standard cho 30 ngày đầu (không có minimum duration), sau đó transition sang Glacier Instant Retrieval hoặc Glacier Flexible Retrieval (minimum 90 ngày). Nếu biết trước pattern này, cấu hình S3 Lifecycle rule:
STANDARD→GLACIERsau 30 ngày. Lưu ý: Standard-IA có minimum 30 ngày — không tiết kiệm nếu object < 30 ngày. -
Sự khác biệt giữa SSE-S3 và SSE-KMS?
Xem đáp án
SSE-S3: AWS quản lý keys hoàn toàn, không có audit trail riêng, miễn phí, không thể control key rotation. SSE-KMS: dùng KMS Customer Managed Key (CMK), mỗi operation tạo CloudTrail entry (audit trail), có thể set key rotation policy, có thể revoke key (block access ngay lập tức), có phí KMS API calls. Compliance environments cần SSE-KMS cho data access audit trail.
-
Khi nào nên dùng S3 Transfer Acceleration?
Xem đáp án
Khi upload từ địa lý xa bucket Region — ví dụ upload từ Vietnam lên us-east-1. Transfer Acceleration route qua Edge Location gần nhất → AWS backbone network → bucket, thay vì đi toàn bộ qua public internet. Hiệu quả nhất cho: uploads > 1 GB từ distance > 1,000 km, mobile apps global, content ingestion từ nhiều continents. Tốc độ test tại: s3-accelerate-speedtest.s3-accelerate.amazonaws.com.
-
S3 Replication có replicate delete markers không?
Xem đáp án
Tùy cấu hình. Mặc định: replication rules không replicate delete markers (S3 chủ ý không tự động propagate deletes để bảo vệ). Bạn có thể bật "Delete marker replication" trong replication rule configuration để replicate delete markers. Permanent deletes (delete specific version) không bao giờ replicate — designed để bảo vệ destination từ accidental/malicious deletes ở source.
-
Minimum object size cho Multi-Part Upload recommendation?
Xem đáp án
AWS khuyến nghị 100 MB — objects lớn hơn nên dùng Multipart Upload. Bắt buộc dùng khi object > 5 GB (single PUT limit). Lợi ích của Multipart: (1) Upload parallel (nhanh hơn), (2) Resumable (resume khi mất kết nối), (3) Retry failed parts mà không restart toàn bộ. Nếu upload fail giữa chừng, cần lifecycle rule để abort incomplete multipart uploads tránh tốn storage.
9. Bài tập thực hành
- Tạo bucket với lifecycle policy
- Enable versioning và test delete/restore
- Configure cross-region replication
- Test S3 event notifications với Lambda
Tài liệu tham khảo chính thức
- Amazon S3 User Guide
- S3 Storage Classes
- S3 Intelligent-Tiering
- Lifecycle Configuration
- S3 Encryption
- S3 Performance Guidelines
- S3 Replication
- S3 Event Notifications
Ngày tiếp theo: Quiz tổng kết Tuần 1