Ravi Sir's Cards › AWS › S3 bucket policies
Amazon S3 bucket policies: public websites, Block Public Access and CloudFront OAC
This page keeps the related S3 bucket-policy cards on one topic page, so you can revise public websites and CloudFront-only access in one sitting. It has the eight cards from “S3 bucket policy project 1: public read-only static website” and the eight cards from “S3 bucket policy project 2: allow only CloudFront via OAC”. Those are the first two packs in the hub’s S3 bucket policy project group (80 cards in total). Later project packs (VPC endpoint, source IP, SSE-KMS, and so on) can be their own topic pages later.
Each card still has its image and its original text. Under each group you will also find a short Why, What, How example, and an exam tip, in easy English. The names, bucket names and URLs in the stories are made up for learning.
Public-read static website and Block Public Access
Why this matters
A small marketing site does not need an application server. Teams still get stuck in two places: they write a public GetObject policy, then Block Public Access silently blocks it; or they open object ACLs one file at a time and later find a file that should never have been public.
What it is
For a cheap public brochure site, you enable S3 website hosting and a bucket policy that allows s3:GetObject for Principal * on object ARNs (the bucket name plus /*). Do not allow public Put or Delete. Block Public Access (BPA) can block public policies or ACLs even when the JSON is valid, so you must plan which BPA flags to clear. Prefer a central bucket policy over per-object public-read ACLs, which drift and are easy to over-share. The website endpoint serves the IndexDocument and ErrorDocument; the REST endpoint does not behave the same way for /. For production sites that need a custom HTTPS domain and WAF, the next group (CloudFront plus OAC) is the better pattern.
How it works — a real example
Suppose Priya Nair hosts a Pune clinic brochure. She creates a bucket, turns on website hosting, uploads index.html and an error page, and puts a bucket policy that allows only public s3:GetObject on the object ARNs. At first the site returns AccessDenied because Block Public Policy is still on. After she allows the public bucket policy (and keeps Block Public ACLs if she is not using ACLs), the website endpoint shows the brochure. People on the internet still cannot upload or delete objects. The name and clinic are made up for learning.
Common mistake / exam tip
If a “perfect” public policy still returns 403, run get-public-access-block before you rewrite the JSON. GetObject needs the object ARN (arn:aws:s3:::site/*); ListBucket needs the bucket ARN. The wrong Resource shape either misses the request or allows too much. And test on the website endpoint if you expect / to show index.html.
Public-read static website
Read card text
What this card says
Why do we need it?
Marketing sites need cheap global reads without an app server.
What is it?
Bucket policy Allow s3:GetObject for Principal * on object ARNs; enable website hosting; open BPA carefully. GetObject
How to do it
Create bucket → website config → policy → upload index/error → test URL → cleanup.
Example
Priya Nair hosts a Pune clinic brochure on S3 website endpoint with public GetObject only.
S3 Block Public Access
Read card text
What this card says
Private by default
Keep all four Block Public Access settings on for a private S3 REST origin behind CloudFront with Origin Access Control (OAC).
Two different checks
BlockPublicPolicy rejects new public policies. RestrictPublicBuckets limits access when a bucket policy is public. Check account-level settings too.
Website endpoint lab
S3 website endpoints cannot use OAC. For an approved public-read lab, scope GetObject tightly to disposable content and restore the guardrails after testing.
Comparison: Public site or CDN edge?
Read card text
What this card says
S3 website public GetObject
Cheap S3 website endpoint; Principal * GetObject; open BPA carefully.
CloudFront + OAC
CloudFront distribution; OAC; deny direct S3.
Key points
Brochure / brochure site with no WAF need. Global site needing HTTPS custom domain and WAF.
Example
put-bucket-website + public GetObject / CreateDistribution + OAC policy
Use when
Tiny marketing pages. Production web with edge controls.
Comparison: Policy or ACL?
Read card text
What this card says
Bucket policy public read
Central JSON; easier audit; works with BPA plan.
Object ACL public-read
Per-object ACL; easy to drift and over-share.
Key points
Site-wide public GetObject. One mistaken public-read object.
Example
put-bucket-policy / put-object-acl
Use when
Prefer for websites. Avoid for new work.
Interview: Which Action for public sites?
Read card text
What this card says
What it is
Usually s3:GetObject on object ARNs for Principal * — never public Put/Delete. GetObject
Why it matters
Pair with website hosting + BPA plan.
How / example
index.html readable; put-object from internet denied.
Interview: Why does public policy still 403?
Read card text
What this card says
What it is
Block Public Access can block public policies even when JSON is valid. BPA
Why it matters
Check get-public-access-block before blaming JSON.
How / example
BlockPublicPolicy true → AccessDenied for anonymous Get.
Interview: Website vs REST endpoint?
Read card text
What this card says
What it is
Website endpoint serves IndexDocument/ErrorDocument; REST does not behave the same for index. website endpoint
Why it matters
Use website endpoint for static hosting demos.
How / example
/ shows index.html only on website endpoint.
Interview: Bucket ARN vs object ARN?
Read card text
What this card says
What it is
GetObject needs object ARN (bucket/*); ListBucket needs bucket ARN. Resource
Why it matters
Wrong Resource shape → silent misses or over-allow.
How / example
Resource arn:aws:s3:::site/* for GetObject.
Allow only CloudFront with Origin Access Control
Why this matters
If the bucket still allows Principal * GetObject, users can skip CloudFront and hit the S3 REST URL. That bypasses WAF, a custom HTTPS domain, and cache controls.
What it is
Origin Access Control (OAC) lets only your CloudFront distribution read the origin. CloudFront signs origin requests, and the bucket policy allows the CloudFront service principal (cloudfront.amazonaws.com) with a Condition on AWS: of that distribution. Do not leave SourceArnPrincipal * GetObject in place. OAC is the modern default: it uses SigV4 and works with SSE-KMS. Origin Access Identity (OAI) is the older canonical-user method, with fewer features; new work should use OAC and old stacks should plan to migrate. End users should use the CloudFront URL, not the direct S3 REST URL.
How it works — a real example
Suppose Kenji Watanabe serves course videos only through CloudFront. He creates an OAC, attaches it to the S3 origin, and puts a bucket policy that allows s3:GetObject only when AWS: is his distribution ARN. Then he tests: curl to the CloudFront URL returns 200, and curl to the raw S3 REST URL returns 403 AccessDenied. Fatima Khan does the same check for news images. The names are made up for learning.SourceArn
Common mistake / exam tip
A typo in the distribution id inside SourceArn will deny CloudFront as well as the public. After you tighten the policy, a cached CloudFront 200 can hide the change — invalidate if you need a fresh test. Never keep Principal * GetObject “as a backup” once OAC is on.
CloudFront OAC only
Read card text
What this card says
Why do we need it?
Direct S3 URLs bypass WAF, HTTPS custom domain, and cache controls.
What is it?
Origin Access Control lets only your distribution read the origin via cloudfront.amazonaws.com + SourceArn. OAC
How to do it
Create OAC → attach to origin → bucket policy Allow GetObject with SourceArn → deny anonymous.
Example
Kenji Watanabe serves course videos only through CloudFront, never the S3 URL.
Deny direct S3 access
Read card text
What this card says
Why do we need it?
If Principal * GetObject remains, users skip CloudFront.
What is it?
Keep Allow only for CloudFront; test curl to S3 REST URL expects AccessDenied. AccessDenied
How to do it
Compare CF URL 200 vs S3 URL 403 after policy.
Example
Fatima Khan confirms news images 403 on raw S3 after OAC policy.
Comparison: OAC or legacy OAI?
Read card text
What this card says
Origin Access Control
SigV4; works with SSE-KMS; modern default.
Origin Access Identity
Legacy canonical user; limited features.
Key points
New CloudFront → S3 origins. Old stacks not yet migrated.
Example
CreateOriginAccessControl / CreateCloudFrontOriginAccessIdentity
Use when
Default for new work. Migrate away from OAI.
Comparison: Edge or origin URL?
Read card text
What this card says
CloudFront URL
Custom domain, WAF, cache, HTTPS at edge.
Direct S3 REST URL
Bypasses edge controls if bucket is open.
Key points
Public media via CDN. Break-glass admin tools only.
Example
curl https://dxxx.cloudfront.net/… / curl https://bucket.s3….amazonaws.com/…
Use when
Always for end users. Never for end users when OAC is on.
Interview: What is CloudFront OAC?
Read card text
What this card says
What it is
Origin Access Control — CloudFront signs origin requests; bucket allows cloudfront.amazonaws.com with SourceArn. OAC
Why it matters
Prefer OAC over legacy OAI.
How / example
Only distro E123 can GetObject.
Interview: Why not Principal * with OAC?
Read card text
What this card says
What it is
Principal * GetObject lets clients skip CloudFront controls (WAF, auth, cache). Principal
Why it matters
Allow only the CloudFront service principal.
How / example
Direct S3 URL 403 after correct policy.
Interview: How do you test OAC deny?
Read card text
What this card says
What it is
Fetch via CloudFront URL (allow) and via S3 REST URL (deny). AccessDenied
Why it matters
Watch for cached CF 200 after policy change — invalidate if needed.
How / example
curl S3 → 403; curl CF → 200.
Interview: Which Condition pins the distribution?
Read card text
What this card says
What it is
AWS:SourceArn of the CloudFront distribution ARN. SourceArn
Why it matters
Typo in distribution id → deny from CF too.
How / example
arn:aws:cloudfront::acct:distribution/Exxx.
FAQ
Which S3 Action should a public website allow?
Usually s3:GetObject on object ARNs for Principal *. Do not allow public Put or Delete.
Why does a valid public bucket policy still return 403?
Block Public Access can block public policies even when the JSON is correct. If BlockPublicPolicy is on, anonymous GetObject is denied. Check get-public-access-block before you blame the policy text.
What is the difference between the website endpoint and the REST endpoint?
The website endpoint serves the IndexDocument and ErrorDocument, so / can show index.html. The REST endpoint does not behave the same way for that index document.
Should I use a bucket policy or an object ACL for a public site?
Prefer a bucket policy. It is one JSON document you can audit. Per-object public-read ACLs are easy to drift. Avoid ACLs for new work.
What is CloudFront OAC?
Origin Access Control. CloudFront signs requests to S3, and the bucket policy allows cloudfront.amazonaws.com only when AWS: matches your distribution. Prefer OAC over the older Origin Access Identity (OAI).SourceArn
How do I test that people cannot skip CloudFront?
Fetch the object via the CloudFront URL (expect 200) and via the S3 REST URL (expect 403 AccessDenied). If CloudFront still shows an old 200, invalidate the cache and test again.
Why not use Principal * GetObject together with OAC?
Principal * GetObject lets clients skip CloudFront, so they also skip WAF, cache rules and your custom HTTPS domain. Allow only the CloudFront service principal.
When is a public S3 website enough, and when do I need CloudFront?
A tiny marketing or brochure site can use the S3 website endpoint with a tight public GetObject policy. A production site that needs a custom HTTPS domain and WAF should use CloudFront plus OAC and deny direct S3 access.
Related lessons
These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):