</>Học Dev
Bài học

Tuần 3 - Ngày 2: S3 Storage Classes

Tuần 3 – Ngày 2

Tuần 3 - Ngày 2: S3 Storage Classes

Mục tiêu học tập

  • Phân biệt 7+ S3 storage classes
  • Hiểu retrieval pricing và minimum duration
  • Biết khi nào dùng Intelligent-Tiering vs lifecycle rules
  • Áp dụng đúng storage class cho mỗi use case

1. Tổng quan Storage Classes

ClassAvailabilityAZsMin durationRetrievalCost
S3 Standard99.99%≥3NoneInstant$$$$
S3 Intelligent-Tiering99.9%≥3NoneInstantAuto-tier
S3 Standard-IA99.9%≥330 daysInstant$$$
S3 One Zone-IA99.5%130 daysInstant$$
S3 Express One Zone99.95%11 hour< 10ms$$$$$
S3 Glacier Instant Retrieval99.9%≥390 daysInstant (ms)$
S3 Glacier Flexible Retrieval99.99%≥390 daysMin-hours$
S3 Glacier Deep Archive99.99%≥3180 days12-48 hours¢
Reduced Redundancy (deprecated)

2. S3 Standard

Đặc điểm

  • Default storage class
  • 99.99% availability
  • 11 nines durability (replicate ≥3 AZs)
  • Không có retrieval fee
  • Không minimum storage duration

Use case

  • Frequently accessed data
  • Static website assets
  • Mobile/gaming applications
  • Big data analytics input
  • Content distribution

3. S3 Intelligent-Tiering

Định nghĩa

S3 tự động move objects giữa các tiers dựa trên access pattern, không tốn retrieval fee, không có operational overhead.

5 tiers

Frequent Access            → Truy cập thường xuyên (Standard-equivalent)
Infrequent Access          → > 30 ngày không truy cập
Archive Instant Access     → > 90 ngày không truy cập (ms retrieval)
Archive Access (optional)  → > 90 ngày (minutes-hours retrieval, opt-in)
Deep Archive (optional)    → > 180 ngày (hours retrieval, opt-in)

Pricing

  • Storage cost theo tier
  • Monitoring fee: $0.0025/1000 objects/month
  • KHÔNG retrieval fee giữa tiers

Use case

  • Data với unknown/changing access patterns
  • "Set and forget" — không muốn manage lifecycle
  • Dài hạn nhiều TB data với access không đoán được

Lưu ý

  • Object < 128 KB luôn ở Frequent tier (không qualify cho tier khác)
  • Auto-archive thì opt-in, mặc định chỉ 2 tier đầu

4. S3 Standard-IA (Infrequent Access)

Đặc điểm

  • Truy cập ít thường xuyên nhưng cần nhanh (instant)
  • 99.9% availability (thấp hơn Standard)
  • Min storage duration: 30 ngày (xóa trước → vẫn tính 30 ngày)
  • Retrieval fee: $/GB
  • Rẻ hơn Standard ~40%

Use case

  • Backup
  • Disaster recovery files
  • Old log files vẫn cần access nhanh

5. S3 One Zone-IA

Đặc điểm

  • Giống Standard-IA nhưng chỉ 1 AZ
  • 99.5% availability
  • Rẻ hơn Standard-IA ~20%
  • Mất data nếu AZ đó destroyed

Use case

  • Reproducible data (có thể regenerate)
  • Secondary backup copies
  • Cached data (replicate được)

6. S3 Express One Zone (2023+)

Đặc điểm

  • Single-digit ms latency — nhanh nhất S3
  • 1 AZ (như One Zone-IA)
  • Min storage duration: 1 hour
  • Cost lớn hơn Standard ~7-8x
  • Performance: hàng triệu req/giây/bucket

Use case

  • AI/ML training data (cần I/O cực nhanh)
  • High-performance analytics
  • Real-time apps

Cấu trúc

  • Tên bucket: my-bucket--use1-az5--x-s3
  • Cần Directory Bucket (kiểu mới, không phải General Purpose Bucket)

7. S3 Glacier (3 tiers)

7.1 Glacier Instant Retrieval

  • Archive với instant ms retrieval (như Standard-IA nhưng rẻ hơn)
  • Min duration: 90 ngày
  • Use case: Quarterly reports, medical images cần retrieve nhanh

7.2 Glacier Flexible Retrieval (cũ "S3 Glacier")

  • Truy cập theo phút - giờ
  • Min duration: 90 ngày
  • 3 retrieval options:
    • Expedited: 1-5 phút (đắt nhất)
    • Standard: 3-5 giờ
    • Bulk: 5-12 giờ (rẻ nhất, ~$0.0025/GB)

7.3 Glacier Deep Archive

  • Rẻ nhất ($0.00099/GB-month)
  • Min duration: 180 ngày
  • Retrieval:
    • Standard: 12 giờ
    • Bulk: 48 giờ
  • Use case: Compliance archive 7-10 năm

So sánh Glacier

ClassRetrievalMin storageCost
Glacier Instantms (instant)90 ngày$$
Glacier FlexibleMin-hours90 ngày$
Glacier Deep Archive12-48 hours180 ngày¢ (cheapest)

8. Lifecycle Rules

Định nghĩa

Tự động transition objects giữa storage classes hoặc expire (delete) sau thời gian.

2 loại action

Transition Action

Object created → 30 ngày → Move to Standard-IA → 90 ngày → Glacier Flexible → 365 ngày → Glacier Deep Archive

Expiration Action

Object created → 7 ngày → Delete
Incomplete multipart uploads → 7 ngày → Delete (cleanup)

Các transitions hợp lệ

StandardStandard-IAGlacierInstantGlacierFlexibleGlacierDeepArchiveOneZone-IAGlacierInstant(skip)

Lưu ý

  • KHÔNG transition từ Glacier về Standard (cần restore + copy)
  • Object < 128 KB không transition (overhead cost > saving)
  • Lifecycle rule áp dụng prefix hoặc tag filter

Ví dụ YAML rule

- Id: ArchiveOldLogs
  Status: Enabled
  Filter:
    Prefix: "logs/"
  Transitions:
    - Days: 30
      StorageClass: STANDARD_IA
    - Days: 90
      StorageClass: GLACIER
    - Days: 365
      StorageClass: DEEP_ARCHIVE
  Expiration:
    Days: 2555  # 7 năm

9. Storage Class Selection Decision Tree

Accesspattern?Truycpthưngxuyên(daily)StandardTruycpít,nhưngcnmslatencyCritical(multi-AZ)Standard-IAReproducible(singleAZOK)OneZone-IAVeryfast(<10ms,1AZ)ExpressOneZoneArchivecnretrievenhanhkhicn(ms)GlacierInstantRetrievalArchiveretrievemin-hoursOKGlacierFlexibleRetrievalArchiveretrievehours-dayOKGlacierDeepArchiveUnknown/changingpatternIntelligent-Tiering

10. Use Case Examples

Ví dụ 1: Web application static assets

  • Hot data (CSS, JS, images frequently accessed)
  • Class: S3 Standard
  • Add: CloudFront để cache thêm

Ví dụ 2: User uploads (photo sharing app)

  • Active: hot in first 30 days
  • Then: cold (rarely viewed)
  • Solution: S3 Standard → Lifecycle to Standard-IA after 30 days → Glacier Instant after 90 days

Ví dụ 3: Backup files

  • Daily backups, rarely retrieve
  • Need access trong vài giờ khi DR
  • Solution: S3 Standard-IA (current) + Lifecycle to Glacier Flexible (90 days) + Deep Archive (1 year)

Ví dụ 4: Compliance logs (giữ 7 năm)

  • Rarely accessed, OK chờ 12 giờ retrieve
  • Solution: Direct to Glacier Deep Archive (qua S3 Standard 1 day để qualify nếu lifecycle)
  • Hoặc upload trực tiếp Deep Archive

Ví dụ 5: ML training data

  • Read intensive khi training
  • Solution: S3 Express One Zone (single-digit ms)

Ví dụ 6: Unknown access pattern, large dataset

  • Data lake mà workload thay đổi theo project
  • Solution: S3 Intelligent-Tiering

11. Pricing Breakdown (Example us-east-1)

ClassStorage $/GB-moRetrieval $/GBPUT/COPY $/1000
Standard$0.023Free$0.005
Standard-IA$0.0125$0.01$0.01
One Zone-IA$0.01$0.01$0.01
Intelligent-Tiering$0.023 (frequent) → $0.00099 (deep)Free between tiers$0.005
Glacier Instant$0.004$0.03$0.02
Glacier Flexible$0.0036$0.01 (std)$0.03
Glacier Deep Archive$0.00099$0.02 (std)$0.05

Giá có thể thay đổi — verify trên AWS Pricing.

12. Storage Class Analysis

Định nghĩa

Tool S3 phân tích access pattern, đề xuất transition to Standard-IA.

Cách dùng

  • Enable Storage Class Analysis trong bucket Management
  • Sau 30 ngày quan sát, output ra CSV report lưu trong S3
  • Visualize: object age vs storage size vs access frequency
  • Tích hợp với Athena / QuickSight để analyze

Tip

  • Đừng đoán → dùng tool để decide lifecycle rules

Câu hỏi ôn tập

  1. Storage class nào có minimum duration charge 180 ngày?

    Xem đáp án

    Glacier Deep Archive (180 ngày minimum storage duration). Nếu delete object trước 180 ngày vẫn bị charge phần còn lại. Các minimum khác: Standard-IA và One Zone-IA = 30 ngày, Glacier Instant Retrieval và Glacier Flexible Retrieval = 90 ngày, Intelligent-Tiering = 30 ngày. Standard và Reduced Redundancy không có minimum.

  2. Khi nào nên dùng S3 Intelligent-Tiering thay vì manual lifecycle?

    Xem đáp án

    Khi access pattern không predictable hoặc thay đổi theo thời gian. Intelligent-Tiering tự động monitor access frequency và move objects giữa tiers (Frequent Access, Infrequent Access, Archive Instant, Archive). Phù hợp cho data analytics, media assets, user-generated content — không biết file nào sẽ được access lại. Manual lifecycle phù hợp khi access pattern rõ ràng (ví dụ: logs cũ hơn 30 ngày không bao giờ access).

  3. Object < 128 KB trong Intelligent-Tiering nằm ở tier nào?

    Xem đáp án

    Frequent Access tierkhông bao giờ bị chuyển xuống tier thấp hơn. S3 không monitor access hoặc charge monitoring fee cho small objects (<128 KB) — overhead của tiering không worth it. Objects nhỏ luôn ở Frequent Access tier. Đây là tối ưu hóa để tránh monitoring cost > storage savings cho small objects.

  4. One Zone-IA rẻ hơn Standard-IA bao nhiêu phần trăm? Trade-off là gì?

    Xem đáp án

    One Zone-IA rẻ hơn ~20% so với Standard-IA. Trade-off: data lưu trong một AZ duy nhất thay vì 3+ AZs — nếu AZ đó bị sự cố hoặc AWS destroy AZ, data bị mất. Phù hợp cho: secondary backups (đã có copy ở nơi khác), easily reproducible data, non-critical data. Không phù hợp cho primary storage của data không thể recreate.

  5. Glacier Flexible Retrieval có mấy options retrieval?

    Xem đáp án

    3 options: (1) Expedited — 1-5 phút, đắt nhất (có thể dùng Provisioned Capacity để đảm bảo), (2) Standard — 3-5 giờ, phí vừa, (3) Bulk — 5-12 giờ, rẻ nhất. Glacier Instant Retrieval (class khác) truy xuất milliseconds như Standard class. Glacier Deep Archive chỉ có Standard (12h) và Bulk (48h).

Bài tập thực hành

  • Upload file vào S3 với 3 storage classes khác nhau (Standard, Standard-IA, Glacier Instant)
  • Tạo Lifecycle rule: transition prefix logs/ đến Standard-IA sau 30 ngày, Glacier sau 90 ngày, expire sau 365 ngày
  • Enable Storage Class Analysis cho bucket
  • Restore object từ Glacier Flexible (Expedited tier) và đo thời gian
  • So sánh giá storage 1 TB cho mỗi class qua Pricing Calculator

Tài liệu tham khảo chính thức


Tiếp theo: S3 Versioning và Lifecycle