Tuần 3 - Ngày 3: S3 Versioning, Replication, Encryption
Mục tiêu học tập
- Hiểu S3 Versioning và MFA Delete
- Phân biệt SRR vs CRR (replication)
- Nắm 4 cơ chế encryption: SSE-S3, SSE-KMS, SSE-C, DSSE-KMS, client-side
- Biết Transfer Acceleration và Multi-Region Access Points
1. S3 Versioning
Định nghĩa
Versioning = lưu nhiều version của 1 object thay vì overwrite.
Đặc điểm
- Tắt mặc định, enable ở bucket level
- Khi enabled:
- Mỗi PUT cùng key → version mới (version ID auto-generated)
- DELETE → tạo delete marker (không xóa thật, version cũ vẫn còn)
- Có thể disable nhưng không thể quay lại "Never enabled" (chỉ pause → "Suspended")
Lifecycle với versioning
- Current version policies
- Non-current version policies (older versions): transition or expire
- Best practice: expire non-current versions sau 30-90 ngày để giảm cost
Restore version cũ
# List versions
aws s3api list-object-versions --bucket my-bucket --prefix file.txt
# Get specific version
aws s3api get-object --bucket my-bucket --key file.txt \
--version-id "abc123" file.txt
Use case
- Protection against accidental delete/overwrite
- Audit trail
- Rollback capability
2. MFA Delete
Định nghĩa
MFA Delete = require MFA code để:
- Permanently delete object version
- Suspend versioning trên bucket
Yêu cầu
- Versioning bật
- Chỉ root user có thể enable MFA Delete (qua CLI, không qua console)
- Root user có MFA device
Enable
aws s3api put-bucket-versioning \
--bucket my-bucket \
--versioning-configuration Status=Enabled,MFADelete=Enabled \
--mfa "arn:aws:iam::111111111111:mfa/root-mfa 123456"
Use case
- Compliance (SOX, HIPAA)
- Protection against insider threat
- Critical data backup
3. S3 Replication
2 loại
- SRR (Same-Region Replication): Replicate trong cùng Region
- CRR (Cross-Region Replication): Replicate sang Region khác
Yêu cầu cho cả hai
- Versioning bật ở source + destination
- IAM role cho S3 replication
- Destination bucket có thể cùng hoặc khác account
Đặc điểm
- Asynchronous replication (không real-time, thường vài giây - phút)
- Chỉ replicate objects mới sau khi enable (objects cũ cần dùng S3 Batch Replication)
- Hỗ trợ:
- Replicate delete markers (optional)
- Replicate replicas (chain replication — bật ở từng bucket)
- Replicate KMS-encrypted objects (cần grant KMS key access)
KHÔNG replicate
- Objects encrypted với SSE-C
- Objects tạo trước khi enable replication (trừ khi dùng S3 Batch Replication)
- Lifecycle actions (transitions/expirations) không replicate
Use cases SRR
- Compliance: 2 copies riêng biệt cùng Region
- Aggregate logs từ nhiều buckets vào 1 central bucket
- Replicate giữa dev và prod accounts
Use cases CRR
- Disaster recovery
- Compliance (data residency cho region khác)
- Lower latency access cho global users
- Cross-account data sharing
S3 Replication Time Control (RTC)
- SLA replicate 99.99% trong 15 phút
- Cost cao hơn standard replication
- Use case: Critical data với strict RPO
S3 Batch Replication
- Replicate existing objects (đã có trong bucket trước khi enable)
- Hoặc replicate objects fail trước đó
- Configure qua S3 Batch Operations
4. S3 Encryption (5 options)
4.1 SSE-S3 (Server-Side Encryption with S3-Managed Keys)
- AWS quản lý hoàn toàn key (AES-256)
- Header:
x-amz-server-side-encryption: AES256 - Mặc định bật cho mọi bucket (từ Jan 2023)
- Free
4.2 SSE-KMS (Server-Side with KMS Keys)
- Key do AWS KMS quản lý
- 2 loại key:
- AWS-managed CMK (alias
aws/s3) — free - Customer-managed CMK — $1/key/month + API calls
- AWS-managed CMK (alias
- Header:
x-amz-server-side-encryption: aws:kms - Audit trail trong CloudTrail (key usage)
- Granular permission qua KMS key policy
- Hỗ trợ bucket key giảm cost KMS API calls
4.3 DSSE-KMS (Dual-Layer SSE with KMS)
- Encrypt 2 lần (defense-in-depth) với KMS keys khác nhau
- Phục vụ regulatory requirements (DoD, government)
- Cost cao gấp đôi SSE-KMS
- 2025: ít dùng trừ compliance đặc biệt
4.4 SSE-C (Server-Side with Customer-Provided Keys)
- Client gửi key qua HTTPS mỗi request
- AWS encrypt/decrypt bằng key đó, không lưu key
- Header:
x-amz-server-side-encryption-customer-key - HTTPS BẮT BUỘC
- Use case: Strict compliance — chỉ client biết key
- Hạn chế: KHÔNG support qua AWS Console
4.5 Client-Side Encryption
- Client encrypt trước khi upload, decrypt sau khi download
- AWS chỉ nhìn thấy ciphertext
- SDK hỗ trợ: AWS Encryption SDK, S3 Encryption Client
- Use case: End-to-end encryption, AWS không bao giờ thấy plaintext
So sánh
| Method | Key managed by | Encryption at | Audit trail | Use case |
|---|---|---|---|---|
| SSE-S3 | AWS (S3) | Server | No (chỉ S3 internal) | Default, đơn giản |
| SSE-KMS | AWS KMS (customer-managed) | Server | Yes (CloudTrail) | Granular control, audit |
| DSSE-KMS | AWS KMS x2 | Server | Yes | Dual-layer compliance |
| SSE-C | Customer | Server | No | Customer giữ key |
| Client-Side | Customer | Client | Lambda layer | Zero-trust |
Force encryption (bucket policy)
{
"Sid": "DenyUnencryptedUploads",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-bucket/*",
"Condition": {
"Null": { "s3:x-amz-server-side-encryption": "true" }
}
}
S3 Bucket Keys (giảm cost SSE-KMS)
- Mặc định: mỗi object encrypt → 1 KMS API call
- Bucket Key: tạo intermediate key, reduce KMS API calls 99%
- Recommended khi dùng SSE-KMS
5. S3 Transfer Acceleration
Định nghĩa
Upload/download S3 qua CloudFront edge locations → fast hơn direct S3.
Workflow
Đặc điểm
- Sử dụng edge optimized AWS backbone sau khi vào edge
- Tăng tốc 50-500% cho global upload
- Endpoint:
bucket.s3-accelerate.amazonaws.com - Cost: $0.04/GB transferred
- Test tool: https://s3-accelerate-speedtest.s3-accelerate.amazonaws.com/
Use case
- Upload từ users xa Region S3
- Large file upload (> 1 GB) cross-continent
6. S3 Multi-Region Access Points (MRAP)
Định nghĩa
Single global endpoint route requests đến nhiều S3 buckets ở multiple Regions.
Workflow
Đặc điểm
- AWS Global Accelerator routes traffic đến bucket nearest user
- Active-active failover: nếu 1 region xuống, route sang region khác
- Endpoint:
mfzwi23gnjvgw.mrap.accesspoint.s3-global.amazonaws.com - Cần enable replication giữa các buckets
Use case
- Global application với users ở nhiều Region
- DR active-active
- Reduce latency cho global reads/writes
7. S3 Access Points
Định nghĩa
Tạo separate access point cho mỗi use case của bucket, mỗi access point có policy riêng.
Đặc điểm
- Mỗi access point có:
- Tên unique (trong account)
- DNS name riêng:
<name>-<account-id>.s3-accesspoint.<region>.amazonaws.com - Policy riêng
- Optional VPC-only (chỉ accessible từ VPC)
- Simplifies large bucket access control với 100+ application/user
Use case
- 1 data lake bucket dùng bởi nhiều team → mỗi team 1 access point với policy riêng
- VPC-restricted access cho internal apps
8. S3 Object Lambda
Định nghĩa
Transform data on-the-fly khi GET object qua Lambda function, không cần duplicate bucket.
Workflow
Client GET → Object Lambda Access Point → S3 Access Point → S3 Bucket
↓
Lambda transform data
↓
Modified data → Client
Use cases
- Redact PII (mask SSN, credit card)
- Resize image dynamically
- Convert format (CSV → JSON)
- Add watermark
- Different views cho different users từ cùng 1 object
9. S3 Storage Lens
Định nghĩa
Storage Lens = analytics dashboard cho S3 usage across organization (all accounts, all buckets).
Đặc điểm
- 30 day metrics free, 15 month historical paid
- Default dashboard: account-wide
- Custom dashboards: filter by Region/account/bucket/prefix
- Recommendations: cost optimization, data protection
Metrics
- Storage usage growth
- Object count
- Number of incomplete multipart uploads
- Bucket-level encryption status
- Top buckets by size, request count
10. S3 Inventory
Định nghĩa
Inventory = daily/weekly CSV/Parquet report liệt kê tất cả objects trong bucket.
Output
- Lưu vào S3 bucket khác
- Format: CSV, ORC, Parquet
- Fields: object key, size, storage class, encryption status, replication status
Use cases
- Bulk operations với S3 Batch
- Audit
- Cost analysis với Athena query
Câu hỏi ôn tập
-
MFA Delete được enable bởi ai? Yêu cầu gì?
Xem đáp án
MFA Delete chỉ có thể enable/disable bởi bucket owner (root account) — không phải IAM user dù có Admin policy. Yêu cầu: (1) bucket phải có versioning enabled, (2) dùng root account với MFA device. Khi bật, xóa object version hoặc thay đổi versioning state đều cần MFA code. Bảo vệ data khỏi ransomware và accidental delete.
-
CRR (Cross-Region Replication) có replicate objects cũ trước khi enable không?
Xem đáp án
Không — CRR (và SRR) chỉ replicate objects sau khi enable replication. Objects đã tồn tại trước đó không được replicate tự động. Nếu cần replicate existing objects, dùng S3 Batch Replication (feature riêng) hoặc copy thủ công. Cũng cần versioning enabled trên cả source lẫn destination bucket.
-
Encryption nào cho phép audit trong CloudTrail?
Xem đáp án
SSE-KMS cho phép audit key usage trong CloudTrail — mỗi lần decrypt object tạo một CloudTrail event với thông tin: who, when, which key. SSE-S3 (AWS-managed key) và SSE-C (customer-provided key) không có granular audit trail. SSE-KMS phù hợp cho compliance environments cần audit trail mọi data access.
-
S3 Transfer Acceleration sử dụng infrastructure nào?
Xem đáp án
AWS Edge Locations (CloudFront network). Upload đi đến Edge Location gần nhất, sau đó AWS routing tối ưu qua AWS backbone network đến S3 bucket. Hiệu quả nhất khi uploading từ xa (cross-continent) vì tránh được phần lớn public internet routing. Có thể test tốc độ tại
s3-accelerate-speedtest.s3-accelerate.amazonaws.com. -
Multi-Region Access Points giải quyết vấn đề gì?
Xem đáp án
Multi-Region Access Points cung cấp single global endpoint cho ứng dụng để access S3 buckets ở nhiều Regions. AWS tự động route requests đến bucket gần nhất (lowest latency) và tự động failover nếu một bucket/Region không khả dụng. Kết hợp với S3 CRR, đây là giải pháp active-active multi-region storage cho global applications.
Bài tập thực hành
- Enable versioning trên bucket, upload 3 versions cùng file, restore version 1
- Setup CRR từ bucket us-east-1 sang ap-southeast-1
- Apply bucket policy force SSE-KMS encryption với customer-managed key
- Enable S3 Bucket Key, monitor KMS API call reduction
- Setup Storage Lens default dashboard, observe top buckets
- Tạo S3 Inventory report daily, query qua Athena
Tài liệu tham khảo chính thức
- S3 Versioning
- S3 Replication
- S3 Encryption
- Transfer Acceleration
- Multi-Region Access Points
- S3 Storage Lens
Tiếp theo: EBS Deep Dive