r/CloudandCode • u/yourclouddude Founder | YourCloudDude • 29d ago
Guide [AWS] Private S3 + CloudFront: the origin endpoint changes the design
Design exercise: visitors should load a static site through CloudFront, while anonymous direct access to the S3 objects stays blocked.
The important distinction
An S3 bucket origin and an S3 website endpoint behave differently. CloudFront Origin Access Control (OAC) supports an S3 bucket origin. An S3 website endpoint is configured as a custom origin and cannot use OAC or OAI.
Sketch the request path
Visitor -> CloudFront -> S3 bucket origin
|
signed origin request
For this design, use the regular S3 bucket origin, configure OAC to sign requests, and grant the CloudFront service principal access through a bucket policy scoped to the intended distribution. Keep S3 Block Public Access enabled. OAC configuration and the bucket policy must work together.
Review these checks
- A known object loads through CloudFront.
- An anonymous direct request to the same S3 object is denied.
- Another distribution is not accidentally allowed by an overly broad bucket policy.
- The default root object is configured if requests to / should serve index.html.
- A genuinely missing asset produces the error behavior you intend.
Avoid masking the wrong failure
Mapping every 403 to index.html may hide permission problems and make missing JavaScript files return HTML. For a single-page application, define a deliberate route-handling strategy and test routes separately from assets.
Practice question: CloudFront returns a cached page after you break its S3 permission. Does that prove the origin access configuration works?
Answer: no. A cache hit can be served without fetching that object from the origin. Verify an origin fetch when checking origin permissions.
You can do the architecture review on paper. If deploying a lab, check service pricing and remove practice resources when finished.
References: S3 origin access, default root objects, CloudFront caching.