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

Ngày 6: S3 và Storage Review

Tuần 1 – Ngày 6

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

ClassAvailabilityDurabilityMin DurationUse Case
Standard99.99%99.999999999%NoneFrequently accessed
Express One Zone99.95%99.999999999%1 hourUltra-low latency (single-digit ms), AI/ML training, request-heavy
Intelligent-Tiering99.9%99.999999999%NoneUnknown pattern
Standard-IA99.9%99.999999999%30 daysInfrequent access
One Zone-IA99.5%99.999999999%30 daysNon-critical, infrequent
Glacier Instant99.9%99.999999999%90 daysArchive, instant access
Glacier Flexible99.99%99.999999999%90 daysArchive, minutes-hours
Glacier Deep Archive99.99%99.999999999%180 daysLong-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

S3Intelligent-TieringFrequentObjectsaccessedAccessTierwithin30daysNoaccess30daysInfrequentAuto-movedAccessTier(40%costsavings)Noaccess90days(opt-in)ArchiveOptionaltierAccessTier(68%costsavings)Noaccess180days(opt-in)DeepArchiveOptionaltierAccessTier(95%costsavings)

Glacier Retrieval Options

TierGlacier FlexibleDeep ArchiveTime
Expedited$$N/A1-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

Day0Day30Day90Day365StandardIAGlacierDELETE

3. S3 Security

Access Control Methods

S3AccessControl1.BucketPolicies(Resource-based)-JSONpolicyattachedtobucket-Cross-accountaccess2.IAMPolicies(Identity-based)-Attachedtousers,groups,roles-Sameaccountonly3.ACLs(Legacy-khôngkhuyếnkhích)-BucketACL/ObjectACL4.AccessPoints-Simplifiedaccessmanagement-Eachwithitsownpolicy

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

Server-SideEncryption(SSE):SSE-S3(Amazonmanagedkeys)-AWSmanageskeysentirely-Header:x-amz-server-side-encryption:AES256SSE-KMS(AWSKMSmanagedkeys)-Morecontroloverkeys-AudittrailinCloudTrail-Header:x-amz-server-side-encryption:aws:kmsSSE-C(Customer-providedkeys)-Customermanageskeys-MustuseHTTPS-ProvidekeywitheachrequestClient-SideEncryption:-Encryptbeforeupload-Customermanageskeysentirely

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

WithoutTransferAcceleration:User(Vietnam)longdistanceS3(us-east-1)WithTransferAcceleration:User(Vietnam)EdgeLocationAWSbackboneS3(us-east-1)(Singapore)

S3 Byte-Range Fetches

LargeFile(10GB)12345Parallelbyte-rangerequestsUsecases:-Paralleldownloads-Resumefaileddownloads-Getspecificportions(headersonly)

6. S3 Replication

Types

FeatureSame-Region (SRR)Cross-Region (CRR)
Use CaseLog aggregationCompliance, DR
LatencyLowHigher
RegionsSameDifferent

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

S3EventsLambdaSNSSQSEventBridge(recommendedforcomplexrouting)

Event Types

  • s3:ObjectCreated:*
  • s3:ObjectRemoved:*
  • s3:ObjectRestore:*
  • s3:Replication:*

8. Câu hỏi ôn tập

  1. 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: STANDARDGLACIER sau 30 ngày. Lưu ý: Standard-IA có minimum 30 ngày — không tiết kiệm nếu object < 30 ngày.

  2. 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.

  3. 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.

  4. 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.

  5. 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


Ngày tiếp theo: Quiz tổng kết Tuần 1