Amazon S3
Object store, not a file system. Exam themes: pick the right storage class, understand replication + lifecycle, and remember the request-rate math per prefix.
Object store, không phải file system. Chủ đề exam: chọn storage class đúng, hiểu replication + lifecycle, và nhớ công thức request-rate theo prefix.
✓ Good fit✓ Hợp
- Immutable / append-only blobs (logs, images, video)Blob immutable / append-only (log, ảnh, video)
- Static-site hosting fronted by CloudFrontStatic site host, CloudFront ở trước
- Data lake / analytics stagingData lake / staging cho analytics
- Backup + tiered archiveBackup + archive tầng
✗ Anti-patterns✗ Anti-pattern
- Millions of tiny (<10 KB) files — request cost eats youHàng triệu file bé (<10 KB) — tốn request cost
- POSIX semantics or file locks → EFS insteadCần POSIX / file lock → EFS
- Search / query workloads → OpenSearch or AthenaSearch / query → OpenSearch hoặc Athena
- Rapidly-mutating rows → DynamoDB / RDSRow thay đổi liên tục → DynamoDB / RDS
Storage classes at a glanceStorage class tổng quan
All classes = 11 9s durability. What changes: availability, AZ count, min-storage-duration, min-billable-size, retrieval fee. IA + Glacier Instant bill min 128 KB per object. Mọi class đều 11 số 9 durability. Khác nhau ở availability, số AZ, min duration, min billable size, retrieval fee. IA + Glacier Instant tính tối thiểu 128 KB mỗi object.
| Class | AvailabilityAvailability | AZsAZ | Min storageMin lưu | RetrievalRetrieval |
|---|---|---|---|---|
| Standard | 99.99% | ≥ 3 | — | — |
| Express One Zone | 99.95% | 1 | — | — · single-digit ms, directory buckets— · vài ms, directory bucket |
| Intelligent-Tiering | 99.9% | ≥ 3 | — | + monitoring fee+ phí monitoring |
| Standard-IA | 99.9% | ≥ 3 | 30 daysngày | /GB |
| One Zone-IA | 99.5% | 1 | 30 daysngày | /GB |
| Glacier Instant | 99.9% | ≥ 3 | 90 daysngày | /GB |
| Glacier Flexible | 99.99% | ≥ 3 | 90 daysngày | /GB |
| Glacier Deep | 99.99% | ≥ 3 | 180 daysngày | /GB |
Retrieval time — how long until I can read it?Thời gian retrieval — bao lâu thì đọc được?
Only two classes make you wait: Glacier Flexible and Deep Archive are offline — you call RestoreObject, wait, and read a temporary copy. Everything else, Glacier Instant included, is a plain GET in milliseconds.
Chỉ hai class bắt chờ: Glacier Flexible và Deep Archive là offline — gọi RestoreObject, chờ, rồi đọc một bản copy tạm. Mọi class còn lại, kể cả Glacier Instant, GET thẳng trong vài mili-giây.
The dashed line is the real divide. Above it the class only changes price; below it the class also changes how you read. Intelligent-Tiering follows the same split: its Frequent / Infrequent / Archive Instant tiers are ms, its opt-in Archive Access and Deep Archive Access tiers behave like Flexible and Deep Archive.
Đường đứt nét mới là ranh giới thật. Phía trên, class chỉ đổi giá; phía dưới, class đổi cả cách đọc. Intelligent-Tiering cũng chia y vậy: tier Frequent / Infrequent / Archive Instant là ms, còn tier opt-in Archive Access và Deep Archive Access hành xử như Flexible và Deep Archive.
| Class · tier | TimeThời gian | Retrieval feePhí retrieval | Reach for it whenChọn khi |
|---|---|---|---|
| Express One Zone | single-digit msvài ms | — | latency-critical, compute in the same AZlatency là trên hết, compute cùng AZ |
| Standard · IA · One Zone-IA | ms | IA: /GBIA: /GB | anything read directlymọi thứ cần đọc thẳng |
| Glacier Instant | ms | /GB · highestcao nhất | read ~once a quarter, but instantlyđọc ~1 lần/quý nhưng phải có ngay |
| Flexible · Expedited | 1–5 minphút | highestcao nhất | urgent restore of a few objectscần gấp vài object |
| Flexible · Standard | 3–5 h | mediumvừa | default restorerestore mặc định |
| Flexible · Bulk | 5–12 h | freemiễn phí | large restores that can wait overnightrestore lớn, chờ qua đêm được |
| Deep Archive · Standard | ≤ 12 h | lowthấp | compliance archive, "within 12 hours"archive compliance, "trong 12 giờ" |
| Deep Archive · Bulk | ≤ 48 h | lowestthấp nhất | petabytes, "within 2 days"hàng petabyte, "trong 2 ngày" |
- A restore is a temporary copy. You pick how many days it lives; the original stays in Flexible / Deep Archive and keeps billing there. To move it for good, restore and then copy it into another class. Restore chỉ tạo bản copy tạm. Bạn chọn số ngày nó tồn tại; bản gốc vẫn nằm ở Flexible / Deep Archive và vẫn tính tiền ở đó. Muốn chuyển hẳn thì restore rồi copy sang class khác.
- Expedited is best-effort — under load it can be refused. Provisioned capacity units guarantee Expedited throughput; that's the answer to "guaranteed retrieval within minutes". Expedited là best-effort — lúc tải cao có thể bị từ chối. Mua Provisioned capacity mới đảm bảo throughput Expedited; đó là đáp án cho "đảm bảo lấy được trong vài phút".
- Restoring millions of objects → S3 Batch Operations with the Standard tier; Flexible restores started this way begin returning data within minutes instead of hours. Restore hàng triệu object → S3 Batch Operations với tier Standard; restore Flexible chạy kiểu này bắt đầu trả dữ liệu sau vài phút thay vì vài giờ.
-
Know when it's done: the
s3:ObjectRestore:Completedevent notification fires per object — wire it to SQS / Lambda / EventBridge instead of polling. Biết khi nào xong: events3:ObjectRestore:Completedbắn cho từng object — nối vào SQS / Lambda / EventBridge thay vì poll.
Cost — where the bill actually comes fromChi phí — hoá đơn thực sự đến từ đâu
Storage per GB is the number everyone compares, and it's rarely the one that bites. Three multipliers do: minimum billable object size, minimum storage duration, and per-request costs. Together they can make a colder class cost more. Giá lưu trữ mỗi GB là con số ai cũng đem ra so, và hiếm khi là thứ gây đau. Ba hệ số nhân mới gây đau: kích thước tối thiểu tính tiền, thời gian lưu tối thiểu, và chi phí theo request. Cộng lại, một class lạnh hơn có thể tốn nhiều hơn.
The minimums are floors, not discounts. Small objects, or objects deleted early, belong in Standard — the colder classes only pay off for large objects that genuinely sit still.
Các mức tối thiểu là sàn, không phải ưu đãi. Object nhỏ, hoặc object xoá sớm, nên nằm ở Standard — các class lạnh chỉ có lãi với object lớn và thực sự nằm yên.
- Transitions cost per request. Moving ten million tiny objects to Glacier can cost more in transition requests than the storage it saves. Lifecycle-transition the big objects; leave small ones alone, or aggregate them first. Transition tính tiền theo request. Chuyển mười triệu object nhỏ sang Glacier có thể tốn tiền request nhiều hơn phần storage tiết kiệm được. Chỉ transition object lớn; object nhỏ để yên, hoặc gộp lại trước.
- Intelligent-Tiering doesn't auto-tier small objects. Objects under 128 KB are never moved to a colder tier and always bill at the Frequent Access rate — you pay the per-object monitoring fee for nothing. It also has no retrieval charges, which is its real selling point. Intelligent-Tiering không tự chuyển tier cho object nhỏ. Object dưới 128 KB không bao giờ được đưa xuống tier lạnh hơn và luôn tính giá Frequent Access — bạn trả phí monitoring mỗi object mà chẳng được gì. Bù lại nó không tính phí retrieval, và đó mới là điểm mạnh thật sự.
- Incomplete multipart uploads are invisible and billed. A failed upload leaves parts that don't show in the object list but occupy storage forever. Add a lifecycle rule to abort incomplete multipart uploads after 7 days — this is the single most common silent S3 cost. Multipart upload dở dang vô hình nhưng vẫn tính tiền. Một lần upload lỗi để lại các part không hiện trong danh sách object nhưng chiếm dung lượng mãi mãi. Thêm lifecycle rule abort incomplete multipart uploads sau 7 ngày — đây là khoản chi phí S3 âm thầm phổ biến nhất.
- On a versioned bucket, deleting an object only adds a delete marker — every old version still bills. Expire noncurrent versions and clean up expired delete markers in the same lifecycle rule. Trên bucket bật versioning, xoá object chỉ thêm một delete marker — mọi version cũ vẫn tính tiền. Hãy expire noncurrent version và dọn expired delete marker trong cùng một lifecycle rule.
PerformancePerformance
Parallelize with multi-part upload (writes) and byte-range fetches (reads). Front global uploads with Transfer Acceleration. Song song hoá bằng multi-part upload (ghi) và byte-range fetch (đọc). Upload toàn cầu thì đặt Transfer Acceleration ở đầu.
AbortIncompleteMultipartUpload · DaysAfterInitiation: 7.
Multi-part upload dở dang vẫn tính tiền. Đặt lifecycle rule AbortIncompleteMultipartUpload · DaysAfterInitiation: 7.
ReplicationReplication
A replication rule is one-way: it lives on the source and copies new objects to the destination. Two-way means two rules. A Multi-Region Access Point sits on top: one global endpoint that routes to the nearest bucket and fails over — but it moves requests, never data. Một replication rule là một chiều: nằm ở bucket nguồn và copy object mới sang đích. Hai chiều nghĩa là hai rule. Multi-Region Access Point nằm ở trên: một endpoint toàn cầu, route tới bucket gần nhất và failover — nhưng nó chuyển request, không bao giờ chuyển dữ liệu.
Read the three panels left to right as a build-up: a rule copies one way; a second rule makes it two-way; an MRAP gives clients a single name for the pair and decides which bucket answers.
Đọc ba khung từ trái qua phải như từng lớp chồng lên: một rule copy một chiều; thêm rule thứ hai thành hai chiều; MRAP cho client một cái tên duy nhất cho cặp bucket và quyết định bucket nào trả lời.
- One-way really is one-way. Writes or deletes in the destination never reach the source. If an app writes in both Regions, a single rule silently loses half the data. Một chiều là một chiều thật. Ghi hay xoá ở bucket đích không bao giờ quay về nguồn. App ghi ở cả hai Region mà chỉ có một rule thì âm thầm mất một nửa dữ liệu.
- Two-way = rule A→B on A + rule B→A on B, and turn on replica modification sync so tag / ACL / Object Lock changes made to a replica flow back too. No loop: a replica is never replicated again. Hai chiều = rule A→B đặt ở A + rule B→A đặt ở B, và bật replica modification sync để thay đổi tag / ACL / Object Lock trên bản replica cũng chảy ngược về. Không bị vòng lặp: replica không bao giờ được replicate tiếp.
- Multi-Region Access Point: one global hostname; requests ride the AWS global network (Global Accelerator) to the lowest-latency bucket. Failover controls flip it active/passive in minutes. Requests must be signed with SigV4A. Multi-Region Access Point: một hostname toàn cầu; request đi trên mạng toàn cầu của AWS (Global Accelerator) tới bucket có latency thấp nhất. Failover controls chuyển sang active/passive trong vài phút. Request phải ký bằng SigV4A.
- MRAP doesn't copy. Without replication between the buckets, a client routed to the other Region reads stale or missing objects. The standard pattern is MRAP + two-way CRR (+ RTC if the RPO needs a number). MRAP không copy dữ liệu. Không có replication giữa các bucket thì client bị route sang Region kia sẽ đọc phải object cũ hoặc thiếu. Mẫu chuẩn là MRAP + CRR hai chiều (+ RTC nếu RPO cần con số cụ thể).
- CRR = cross-region · SRR = same-region. Both require versioning on source + destination. CRR = khác region · SRR = cùng region. Cả hai đều cần versioning ở source + đích.
- Combine with Lifecycle Rules to tier the destination cheaper than the source. Kết hợp Lifecycle để đích tier rẻ hơn source.
- S3 RTC — SLA-backed replication, 99.99% under 15 min. Use for compliance / cross-region DR. S3 RTC — replication có SLA, 99.99% dưới 15 phút. Dùng cho compliance / DR đa region.
- Only new objects replicate — backfill existing ones with S3 Batch Replication. Delete markers replicate only if opted in; deletes of versions never replicate. No chaining A→B→C. Chỉ object mới được replicate — object cũ phải chạy S3 Batch Replication. Delete marker chỉ replicate nếu bật; xoá version thì không bao giờ replicate. Không chain A→B→C.
Event notificationsEvent notifications
Fire on ObjectCreated, ObjectRemoved, ObjectRestore, Replication. Filter by suffix (e.g. *.jpg).
Kích hoạt trên ObjectCreated, ObjectRemoved, ObjectRestore, Replication. Filter theo suffix (vd *.jpg).
| Native S3 notificationsNative S3 | Via EventBridgeQua EventBridge | |
|---|---|---|
| DestinationsĐích | SQS · SNS · Lambda | Step Functions · Kinesis · Firehose · many morev.v. |
| FilteringFilter | prefix / suffixprefix / suffix | JSON rules on metadata, size, nameJSON rule trên metadata, size, name |
| ExtrasBổ sung | — | Archive · replay · reliable deliveryArchive · replay · giao đúng |
Logging — CloudTrail vs server access logsLogging — CloudTrail vs server access logs
CloudTrail records who called which API (an IAM identity) with guaranteed delivery — that's audit. Server access logs record every HTTP request (bytes, timing, user-agent) almost for free, but best-effort. And CloudTrail only sees object reads/writes if you turn on data events. CloudTrail ghi ai gọi API nào (danh tính IAM), có cam kết giao log — đó là audit. Server access logs ghi từng HTTP request (byte, thời gian, user-agent) gần như miễn phí, nhưng chỉ best-effort. Và CloudTrail chỉ thấy thao tác đọc/ghi object khi bạn bật data events.
The trap is the middle row: CloudTrail is on by default, so it feels like everything is logged — but only bucket-level calls are. Object-level calls need data events switched on.
Bẫy nằm ở hàng giữa: CloudTrail bật sẵn nên có cảm giác mọi thứ đều được ghi — nhưng chỉ thao tác cấp bucket thôi. Thao tác cấp object phải bật data events.
| CloudTrail management | CloudTrail data events | Server access logs | |
|---|---|---|---|
| ScopePhạm vi | bucket-level APIAPI cấp bucket | object-level APIAPI cấp object | every request, bucket + objectmọi request, bucket + object |
| Turn onBật | on by default (90 d history; trail for longer)bật sẵn (giữ 90 ngày; lâu hơn cần trail) | opt-in on a trail · filter by bucket / prefix / read-writetự bật trên trail · lọc theo bucket / prefix / đọc-ghi | per bucket → target buckettừng bucket → bucket đích |
| CostChi phí | first copy freebản đầu miễn phí | per event — expensive on hot bucketstheo event — đắt với bucket nóng | storage onlychỉ phí lưu |
| DeliveryGiao log | guaranteed · log file validationđảm bảo · log file validation | guaranteed · log file validationđảm bảo · log file validation | best-effort — can be late or missingbest-effort — có thể trễ hoặc thiếu |
| Stands outĐiểm riêng | IAM ARN, source IP · CloudTrail Lake, EventBridgeIAM ARN, source IP · CloudTrail Lake, EventBridge | same, per objectnhư trên, cho từng object | HTTP status, bytes, latency, referer, anonymous hits, lifecycle actionsHTTP status, byte, latency, referer, request ẩn danh, hành động lifecycle |
- Never log a bucket into itself. Each log write is a request, which is logged, which is a write… Use a separate target bucket in the same Region. Đừng ghi access log vào chính bucket đó. Mỗi lần ghi log là một request, lại được log, lại là một lần ghi… Dùng bucket đích riêng, cùng Region.
- Event notifications are not logs. They tell a consumer "something happened" so it can react; they aren't a complete, tamper-evident record. Event notification không phải log. Nó báo cho consumer "có chuyện xảy ra" để phản ứng; không phải bản ghi đầy đủ, chống sửa.
- For tamper-proof audit, send the trail to a dedicated bucket with Object Lock and turn on log file validation; in an Organization, use an org trail into a log-archive account. Audit chống sửa: trail đổ vào bucket riêng có Object Lock và bật log file validation; trong Organization dùng org trail đổ về account log-archive.
Storage Lens vs Storage Class AnalysisStorage Lens vs Storage Class Analysis
- Storage Class Analysis — decides when to move Standard → Standard-IA. Bucket-level. Daily report. Skip if you're on One Zone-IA or Glacier. Storage Class Analysis — quyết định khi nào chuyển Standard → Standard-IA. Cấp bucket. Report hằng ngày. Không dùng nếu đang One Zone-IA / Glacier.
- Storage Lens — org-wide storage & cost insight. Free = 28 metrics for 14 days; Advanced = 15 months + prefix aggregation + CloudWatch publish. Storage Lens — nhìn tổng thể toàn org. Free = 28 metric giữ 14 ngày; Advanced = 15 tháng + gộp prefix + publish CloudWatch.
Encryption at rest — SSE-what?Mã hoá at rest — SSE-cái gì?
SSE = server-side encryption: S3 encrypts the object after it arrives and decrypts it on the way out. TLS protects data in transit; SSE protects it at rest. The suffix after the dash only ever answers one question: who manages the key. SSE = server-side encryption: S3 mã hoá object sau khi nó tới và giải mã lúc gửi ra. TLS bảo vệ dữ liệu đang truyền; SSE bảo vệ dữ liệu lúc nằm yên. Phần sau dấu gạch chỉ trả lời đúng một câu: ai quản lý key.
SSE-S3 (AES256) |
SSE-KMS · aws/s3 |
SSE-KMS · CMK | SSE-C | |
|---|---|---|---|---|
| Who manages the keyAi quản lý key | S3 | AWS | you — policy & lifecyclebạn — policy & vòng đời | you, outside AWS entirelybạn, hoàn toàn ngoài AWS |
| Visible in the KMS consoleThấy trong KMS console | ✗ | ✓ metadata only✓ chỉ metadata | ✓ | ✗ |
| Edit key policy · disable · schedule deletionSửa key policy · disable · hẹn xoá | ✗ | ✗ | ✓ | — |
| Per-key CloudTrail audit of every useAudit CloudTrail từng lần dùng key | ✗ | ✓ | ✓ | ✗ |
| Cross-account grants on the keyCấp quyền cross-account trên key | ✗ | ✗ | ✓ | — |
| Caller must send the key on every requestCaller phải gửi key trong mọi request | ✗ | ✗ | ✗ | ✓ — every PUT/GET/HEAD✓ — mọi PUT/GET/HEAD |
| Extra costPhí thêm | nonekhông | KMS requestsrequest KMS | KMS key + requestskey KMS + request | nonekhông |
aws/s3 (AWS owns it), and not SSE-C — SSE-C makes the application carry a secret in every request, which is the opposite of what a security team wants. There is also no such thing as "SSE-S3 with a customer managed key", and picking AES256 in the console is SSE-S3.
"Key do security team của công ty quản lý" ⇒ SSE-KMS với customer-managed key. Không phải SSE-S3 (S3 sở hữu), không phải aws/s3 (AWS sở hữu), và không phải SSE-C — SSE-C bắt ứng dụng mang secret trong mọi request, ngược hẳn với thứ security team muốn. Cũng không có cái gọi là "SSE-S3 với customer managed key", và chọn AES256 trong console chính là SSE-S3.
This is envelope encryption, and it's why a KMS key can protect petabytes: the KMS key never touches your data, it only wraps the per-object data key.
Đây là envelope encryption, và là lý do một KMS key bảo vệ được cả petabyte: KMS key không bao giờ chạm vào dữ liệu của bạn, nó chỉ bọc data key của từng object.
aws s3 cp --recursive in place, S3 Batch Operations copy, or CopyObject onto itself with the new encryption. Any answer that claims a bucket policy will "encrypt objects on GetObject" is inventing behaviour: reading never re-encrypts, and a bucket policy can only reject a request, never transform it.
Đổi default encryption của bucket không làm gì với các object đã nằm sẵn. Muốn chuyển thì phải ghi lại từng cái — aws s3 cp --recursive tại chỗ, S3 Batch Operations copy, hoặc CopyObject lên chính nó với encryption mới. Đáp án nào nói bucket policy sẽ "mã hoá object khi GetObject" là bịa hành vi: đọc không bao giờ mã hoá lại, và bucket policy chỉ từ chối được request, không biến đổi được nó.
- Enforce the rule with a bucket policy that denies
PutObjectwhens3:x-amz-server-side-encryptionisn'taws:kms, or whens3:x-amz-server-side-encryption-aws-kms-key-idisn't your key ARN.Ép luật bằng bucket policy denyPutObjectkhis3:x-amz-server-side-encryptionkhông phảiaws:kms, hoặc khis3:x-amz-server-side-encryption-aws-kms-key-idkhông phải ARN key của bạn. - If versioning is on, rewriting an object leaves the old, differently-encrypted version behind. You have to deal with noncurrent versions too — with versioning off, the rewrite simply overwrites.Nếu versioning đang bật, ghi lại object sẽ để lại version cũ mã hoá kiểu cũ. Phải xử lý cả noncurrent version — nếu versioning tắt, ghi lại là ghi đè luôn.
- Reading an SSE-KMS object needs
kms:Decrypton the key as well ass3:GetObject. A cross-account reader who has the bucket policy but not the key grant gets AccessDenied — this is the most common "but I gave them access" bug.Đọc object SSE-KMS cầnkms:Decrypttrên key ngoàis3:GetObject. Bên đọc cross-account có bucket policy mà không có grant trên key sẽ nhận AccessDenied — đây là lỗi "tôi đã cấp quyền rồi mà" phổ biến nhất. - SSE-C: S3 stores only a salted HMAC of your key to validate later requests, never the key. Lose the key, lose the data. HTTPS is mandatory.SSE-C: S3 chỉ lưu một HMAC có salt của key để kiểm tra request sau, không bao giờ lưu key. Mất key là mất dữ liệu. Bắt buộc HTTPS.
- DSSE-KMS applies two independent layers of KMS encryption — a compliance-mandated option, not a performance one.DSSE-KMS áp hai lớp mã hoá KMS độc lập — lựa chọn do compliance bắt buộc, không phải để chạy nhanh hơn.
- Turn on S3 Bucket Keys for KMS-encrypted buckets: S3 caches a bucket-level key and cuts KMS request charges dramatically on high-volume buckets.Bật S3 Bucket Keys cho bucket mã hoá bằng KMS: S3 cache một key ở mức bucket và giảm mạnh phí request KMS trên bucket lưu lượng cao.