Ravindra BagaleCourses & study guides मराठी Track your progress

Ravi Sir's Cards › AWS › S3 bucket policies

AWS Cloud

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

Revision card: Public-read static website. Marketing sites need cheap global reads without an app server. Bucket policy Allow s3:GetObject for Principal * on object ARNs; enable website hosting; open BPA carefully. Create bucket → website config → policy → upload index/error → test URL → cleanup. Priya Nair hosts a Pune clinic brochure on S3 website endpoint with public GetObject only.
Card 1 of 16: Public-read static website · Download PNG
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

S3 Block Public Access. Keep all four Block Public Access settings on for a private S3 REST origin behind CloudFront with Origin Access Control (OAC). BlockPublicPolicy rejects new public policies. RestrictPublicBuckets limits access when a bucket policy is public. Check account-level settings too. S3 website endpoints cannot use OAC. For an approved public-read lab, scope GetObject tightly to disposable content and restore the guardrails after testing.
Card 2 of 16: S3 Block Public Access · Download PNG
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?

Comparison: S3 website public GetObject vs CloudFront + OAC. S3 website public GetObject: Cheap S3 website endpoint; Principal * GetObject; open BPA carefully. CloudFront + OAC: CloudFront distribution; OAC; deny direct S3.
Card 3 of 16: Comparison: Public site or CDN edge? · Download PNG
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?

Comparison: Bucket policy public read vs Object ACL public-read. 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.
Card 4 of 16: Comparison: Policy or ACL? · Download PNG
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?

Interview card: Which Action for public sites?. Usually s3:GetObject on object ARNs for Principal * — never public Put/Delete. Pair with website hosting + BPA plan. index.html readable; put-object from internet denied.
Card 5 of 16: Interview: Which Action for public sites? · Download PNG
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?

Interview card: Why does public policy still 403?. Block Public Access can block public policies even when JSON is valid. Check get-public-access-block before blaming JSON. BlockPublicPolicy true → AccessDenied for anonymous Get.
Card 6 of 16: Interview: Why does public policy still 403? · Download PNG
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?

Interview card: Website vs REST endpoint?. Website endpoint serves IndexDocument/ErrorDocument; REST does not behave the same for index. Use website endpoint for static hosting demos. / shows index.html only on website endpoint.
Card 7 of 16: Interview: Website vs REST endpoint? · Download PNG
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?

Interview card: Bucket ARN vs object ARN?. GetObject needs object ARN (bucket/*); ListBucket needs bucket ARN. Wrong Resource shape → silent misses or over-allow. Resource arn:aws:s3:::site/* for GetObject.
Card 8 of 16: Interview: Bucket ARN vs object ARN? · Download PNG
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:SourceArn of that distribution. Do not leave Principal * 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:SourceArn 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.

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

Revision card: CloudFront OAC only. Direct S3 URLs bypass WAF, HTTPS custom domain, and cache controls. Origin Access Control lets only your distribution read the origin via cloudfront.amazonaws.com + SourceArn. Create OAC → attach to origin → bucket policy Allow GetObject with SourceArn → deny anonymous. Kenji Watanabe serves course videos only through CloudFront, never the S3 URL.
Card 9 of 16: CloudFront OAC only · Download PNG
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

Revision card: Deny direct S3 access. If Principal * GetObject remains, users skip CloudFront. Keep Allow only for CloudFront; test curl to S3 REST URL expects AccessDenied. Compare CF URL 200 vs S3 URL 403 after policy. Fatima Khan confirms news images 403 on raw S3 after OAC policy.
Card 10 of 16: Deny direct S3 access · Download PNG
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?

Comparison: Origin Access Control vs Origin Access Identity. Origin Access Control: SigV4; works with SSE-KMS; modern default. Origin Access Identity: Legacy canonical user; limited features.
Card 11 of 16: Comparison: OAC or legacy OAI? · Download PNG
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?

Comparison: CloudFront URL vs Direct S3 REST URL. CloudFront URL: Custom domain, WAF, cache, HTTPS at edge. Direct S3 REST URL: Bypasses edge controls if bucket is open.
Card 12 of 16: Comparison: Edge or origin URL? · Download PNG
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?

Interview card: What is CloudFront OAC?. Origin Access Control — CloudFront signs origin requests; bucket allows cloudfront.amazonaws.com with SourceArn. Prefer OAC over legacy OAI. Only distro E123 can GetObject.
Card 13 of 16: Interview: What is CloudFront OAC? · Download PNG
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?

Interview card: Why not Principal * with OAC?. Principal * GetObject lets clients skip CloudFront controls (WAF, auth, cache). Allow only the CloudFront service principal. Direct S3 URL 403 after correct policy.
Card 14 of 16: Interview: Why not Principal * with OAC? · Download PNG
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?

Interview card: How do you test OAC deny?. Fetch via CloudFront URL (allow) and via S3 REST URL (deny). Watch for cached CF 200 after policy change — invalidate if needed. curl S3 → 403; curl CF → 200.
Card 15 of 16: Interview: How do you test OAC deny? · Download PNG
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?

Interview card: Which Condition pins the distribution?. AWS:SourceArn of the CloudFront distribution ARN. Typo in distribution id → deny from CF too. arn:aws:cloudfront::acct:distribution/Exxx.
Card 16 of 16: Interview: Which Condition pins the distribution? · Download PNG
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:SourceArn matches your distribution. Prefer OAC over the older Origin Access Identity (OAI).

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.

These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):

See all AWS revision cards