Bài này gộp 3 chủ đề: Amazon S3 Fundamentals, S3 Storage Classes, S3 Versioning, Replication, Encryption.
Mục tiêu học tập
- Hiểu khái niệm bucket, object, key
- Nắm S3 access control: bucket policy, ACL, IAM, Block Public Access
- Hiểu durability, availability, region của S3
- Biết các tính năng cơ bản: hosting, presigned URL, CORS
- 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
- Hiểu S3 Versioning và MFA Delete
- Phân biệt SRR vs CRR (replication)
- Nắm 5 cơ chế encryption: SSE-S3, SSE-KMS, SSE-C, DSSE-KMS, client-side
- Biết Transfer Acceleration và Multi-Region Access Points
Phần 1: Amazon S3 Fundamentals
1. Tổng quan S3
Amazon S3 (Simple Storage Service) = object storage service với:
- 99.999999999% (11 nines) durability
- 99.99% availability (Standard class)
- Unlimited storage, object size lên đến 50 TB (trước 12/2025 là 5 TB — đề thi có thể còn dùng số cũ)
- Pay-as-you-go: $/GB-month + requests + data transfer
S3 trong Solutions Architecture
| Use case | Service S3 |
|---|---|
| Static website hosting | S3 + CloudFront |
| Backup & archive | S3 + Glacier |
| Data lake | S3 + Athena/Redshift Spectrum |
| Big data analytics | S3 + EMR |
| Media storage | S3 (image, video) |
| Software distribution | S3 + presigned URL |
| Log storage | S3 (centralized logs) |
2. Bucket và Object
Bucket
- Container chứa objects
- Bucket name unique globally (không phải chỉ trong account)
- Name rules: 3-63 chars, lowercase, không underscore, format DNS-compliant
- Bucket được tạo trong 1 Region
- Soft limit: 100 buckets/account (có thể tăng lên 1000)
Object
- Key = full path (ví dụ:
folder/subfolder/file.txt) - Value = nội dung (binary, text, image...)
- Metadata: system + user-defined headers
- Tags: key-value (lên đến 10 tags/object)
- Version ID (nếu versioning enabled)
- Max object size 50 TB (số cũ: 5 TB), max upload single PUT 5 GB (lớn hơn cần multipart)
URL Format
Path-style (legacy):
https://s3.us-east-1.amazonaws.com/my-bucket/path/to/file.txt
Virtual-hosted style (recommended):
https://my-bucket.s3.us-east-1.amazonaws.com/path/to/file.txt
AWS khuyến nghị virtual-hosted style; kế hoạch loại bỏ path-style đã bị hoãn vô thời hạn — path-style hiện vẫn hoạt động nhưng sẽ bị loại bỏ trong tương lai.
3. Durability vs Availability
Durability (Độ bền)
- 99.999999999% (11 nines) cho mọi storage class
- 1 object/10 triệu/10,000 năm có thể bị mất
- Replicated across multiple AZs trong cùng Region (trừ One Zone class)
Availability (Độ sẵn sàng)
- Khác nhau theo storage class:
- Standard: 99.99%
- Standard-IA: 99.9%
- One Zone-IA: 99.5%
- Glacier Instant: 99.9%
4. S3 Region
Đặc điểm
- S3 bucket tạo trong 1 Region
- Data không rời Region (trừ khi bạn replicate)
- Bucket name unique global nhưng data lưu regional
Latency
- Truy cập từ cùng Region: ms
- Truy cập từ Region khác: cao hơn, có thể tăng tốc bằng:
- Transfer Acceleration (qua CloudFront edge)
- Multi-Region Access Points
5. Access Control (4 mechanisms)
Hierarchy của Access Control
1. Block Public Access (account/bucket level) → override mọi thứ khác
2. IAM Policy (identity-based)
3. Bucket Policy (resource-based)
4. ACL (legacy, không khuyến nghị)
5. Object-level Permission
5.1 Block Public Access (BPA)
- Setting bật mặc định cho bucket mới (từ 2023)
- 4 sub-settings:
- Block public ACLs
- Ignore public ACLs
- Block public bucket policies
- Restrict public bucket access (cho cross-account)
- Override mọi policy → bucket KHÔNG public dù policy allow
5.2 IAM Policy
- Gắn vào IAM user/group/role
- Format JSON quen thuộc
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::my-bucket/*"
}]
}
5.3 Bucket Policy (Resource-based)
- Gắn vào bucket
- Bắt buộc có Principal
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-public-bucket/*"
}]
}
Use cases bucket policy
- Cross-account access
- Force HTTPS only (
"aws:SecureTransport": "true") - Force encryption (
"s3:x-amz-server-side-encryption": "AES256") - IP restriction (
"aws:SourceIp") - VPC Endpoint restriction (
"aws:SourceVpce")
Ví dụ: Force HTTPS
{
"Sid": "DenyHTTP",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-bucket",
"arn:aws:s3:::my-bucket/*"
],
"Condition": {
"Bool": { "aws:SecureTransport": "false" }
}
}
5.4 ACL (Access Control List) — Legacy
- Permission cho object/bucket dạng XML
- Khuyến nghị TẮT ACL (default cho bucket mới từ 2023)
- Setting "Object Ownership": Bucket owner enforced → tắt ACL
6. Static Website Hosting
Setup
- Enable "Static website hosting" trong bucket Properties
- Set index document:
index.html - Set error document:
error.html - Make bucket public (disable BPA, add bucket policy)
Endpoint
http://my-bucket.s3-website-us-east-1.amazonaws.com
hoặc
http://my-bucket.s3-website.us-east-1.amazonaws.com
Lưu ý
- HTTP only, không HTTPS (cần CloudFront cho HTTPS)
- Cần custom domain → Route 53 alias hoặc CNAME
- Best practice: S3 (private) + CloudFront + OAC
7. Presigned URL
Định nghĩa
URL có temporary credentials embedded, cho phép thực hiện 1 action (GET/PUT) trên S3 object trong thời gian giới hạn.
Use case
- Cho phép user download private file (Premium content)
- Upload file trực tiếp từ client lên S3 (không qua backend)
- Sharing file ngắn hạn
Tạo qua CLI
aws s3 presign s3://my-bucket/private-file.pdf --expires-in 3600
# Output: https://my-bucket.s3.amazonaws.com/private-file.pdf?X-Amz-Algorithm=...
Expiration
- CLI default: 3600s (1 hour)
- Max: 7 ngày (SigV4, với IAM user credentials dài hạn)
- Với temporary credentials (IAM role): URL chỉ sống bằng thời hạn session của credentials (role session max 12 giờ); tạo từ console max 12 giờ
8. CORS (Cross-Origin Resource Sharing)
Khi nào cần?
- Browser ở domain A gọi S3 ở domain B
- Browser check CORS preflight
Configuration
Trong bucket → Permissions → CORS:
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "PUT", "POST"],
"AllowedOrigins": ["https://example.com"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3000
}
]
9. Object Operations cơ bản
Upload
# Single file
aws s3 cp local.txt s3://my-bucket/
# Folder
aws s3 sync ./local-folder s3://my-bucket/remote-folder/
# Multipart upload (auto cho file > 8 MB qua CLI)
aws s3 cp big-file.zip s3://my-bucket/
Multipart Upload
- Tự động khi file > 8 MB (qua CLI/SDK)
- Bắt buộc cho file > 5 GB
- Lợi ích:
- Resume nếu fail
- Parallel upload nhanh hơn
- Mỗi part: 5 MB - 5 GB (trừ part cuối)
- Lưu ý: Multipart fails → incomplete parts vẫn tính phí (dọn dẹp qua Lifecycle rule)
Download
aws s3 cp s3://my-bucket/file.txt ./
aws s3 sync s3://my-bucket/folder/ ./local/
Delete
aws s3 rm s3://my-bucket/file.txt
aws s3 rm s3://my-bucket/folder/ --recursive
10. S3 Strong Consistency
Định nghĩa
Strong read-after-write consistency cho TẤT CẢ operations (từ Dec 2020):
- PUT new object → GET ngay lập tức = read được
- UPDATE (PUT cùng key) → GET ngay = read version mới
- DELETE → GET = 404 ngay
Lưu ý
- Trước Dec 2020: chỉ eventual consistency cho UPDATE/DELETE
- Hiện tại: strong consistency 100%, không tăng cost, no perf impact
11. S3 Object Lock
Định nghĩa
Object Lock = WORM (Write Once Read Many): prevent delete/overwrite của object trong khoảng thời gian.
Modes
- Governance Mode: User có
s3:BypassGovernanceRetentioncó thể remove lock - Compliance Mode: KHÔNG AI có thể delete/modify (kể cả root)
Retention
- Retain until date: Set timestamp
- Legal Hold: Indefinite hold, no expiration (chỉ user với permission remove được)
Use case
- Compliance (SEC Rule 17a-4, FINRA, HIPAA)
- Backup chống ransomware
- Audit logs cần immutable
12. S3 Replication (Brief — chi tiết ở Phần 3 bên dưới)
2 loại
- Same-Region Replication (SRR): Replicate trong cùng Region
- Cross-Region Replication (CRR): Replicate sang Region khác
Yêu cầu
- Versioning bật ở cả source và destination bucket
- IAM role với quyền replicate
- Destination bucket exist (cùng hoặc khác account)
Phần 2: S3 Storage Classes
1. Tổng quan Storage Classes
| Class | Availability | AZs | Min duration | Retrieval | Cost |
|---|---|---|---|---|---|
| S3 Standard | 99.99% | ≥3 | None | Instant | $$$$ |
| S3 Intelligent-Tiering | 99.9% | ≥3 | None | Instant | Auto-tier |
| S3 Standard-IA | 99.9% | ≥3 | 30 days | Instant | $$$ |
| S3 One Zone-IA | 99.5% | 1 | 30 days | Instant | $$ |
| S3 Express One Zone | 99.95% | 1 | 1 hour | < 10ms | $$$$$ |
| S3 Glacier Instant Retrieval | 99.9% | ≥3 | 90 days | Instant (ms) | $ |
| S3 Glacier Flexible Retrieval | 99.99% | ≥3 | 90 days | Min-hours | $ |
| S3 Glacier Deep Archive | 99.99% | ≥3 | 180 days | 12-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ờ (miễn phí — Bulk retrieval FREE với Glacier Flexible Retrieval)
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
| Class | Retrieval | Min storage | Cost |
|---|---|---|---|
| Glacier Instant | ms (instant) | 90 ngày | $$ |
| Glacier Flexible | Min-hours | 90 ngày | $ |
| Glacier Deep Archive | 12-48 hours | 180 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ệ
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
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)
| Class | Storage $/GB-mo | Retrieval $/GB | PUT/COPY $/1000 |
|---|---|---|---|
| Standard | $0.023 | Free | $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
Phần 3: S3 Versioning, Replication, Encryption
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 | N/A (AWS không thấy plaintext) | 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
-
Object S3 max size là bao nhiêu? Multipart upload bắt buộc khi file > ?
Xem đáp án
Object max size là 50 TB (từ 12/2025; trước đó là 5 TB — đề thi có thể còn dùng số cũ). Single PUT upload max là 5 GB — nếu file > 5 GB bắt buộc dùng Multipart Upload. AWS khuyến nghị dùng Multipart Upload cho file > 100 MB (để tận dụng parallel upload, resumable, và tốc độ nhanh hơn). Multipart Upload có thể upload lên đến 10,000 parts, mỗi part 5 MB - 5 GB.
-
S3 bucket name có unique global không?
Xem đáp án
Có — bucket name unique across toàn bộ AWS (all accounts, all Regions). Đây là vì S3 dùng bucket name trong URL:
https://bucket-name.s3.amazonaws.com/. Tuy nhiên bucket được tạo trong một Region cụ thể — data lưu tại Region đó. Namespace global nhưng data regional. -
Block Public Access có override bucket policy public không?
Xem đáp án
Có. Block Public Access (BPA) là layer cao nhất — kể cả khi bucket policy cho phép public access, BPA vẫn block. BPA có thể set ở account level (áp dụng cho tất cả buckets) hoặc bucket level. Khi BPA bật, mọi bucket policy/ACL granting public access đều bị override. Best practice: bật BPA ở account level, chỉ tắt cho từng bucket khi thực sự cần public.
-
Static website hosting trên S3 có hỗ trợ HTTPS không?
Xem đáp án
Không trực tiếp — S3 static website endpoint chỉ hỗ trợ HTTP. Để có HTTPS, đặt CloudFront trước S3 bucket: CloudFront terminate TLS với ACM certificate, serve content từ S3 via HTTPS. Đây là pattern phổ biến nhất cho static website: S3 (origin) + CloudFront (HTTPS + CDN + custom domain).
-
Strong consistency cho S3 áp dụng từ năm nào?
Xem đáp án
Từ tháng 12/2020. Trước đó S3 có eventual consistency cho overwrite PUT và DELETE. Kể từ 2020, S3 cung cấp strong read-after-write consistency cho tất cả operations (PUT, GET, DELETE, LIST) — ngay sau khi write thành công, read sẽ thấy data mới nhất. Không cần giải pháp workaround nào nữa để đảm bảo consistency.
-
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.
-
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).
-
Object < 128 KB trong Intelligent-Tiering nằm ở tier nào?
Xem đáp án
Frequent Access tier và khô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.
-
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.
-
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).
- 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
Phần 1: Amazon S3 Fundamentals
- Tạo bucket private, upload vài file
- Tạo bucket public với static website hosting, deploy 1 trang HTML
- Tạo presigned URL cho 1 object, expires 5 phút
- Apply bucket policy force HTTPS, test với HTTP request bị deny
- Enable Object Lock với Compliance mode 7 ngày, thử delete
- Setup CORS cho bucket cho phép origin
https://example.com
Phần 2: S3 Storage Classes
- 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
Phần 3: S3 Versioning, Replication, Encryption
- 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
- Amazon S3 User Guide
- S3 Bucket Policy Examples
- Block Public Access
- Presigned URLs
- Object Lock
- S3 Storage Classes
- Intelligent-Tiering
- Glacier Storage Classes
- S3 Lifecycle Configuration
- Storage Class Analysis
- S3 Versioning
- S3 Replication
- S3 Encryption
- Transfer Acceleration
- Multi-Region Access Points
- S3 Storage Lens