Skip to main content
This walkthrough demonstrates the difference between serving static content directly from an Amazon S3 bucket versus serving it through Amazon CloudFront. The goal is to illustrate how CloudFront sits between users and an origin (S3), caching content at edge locations to improve performance and keep your origin private and secure. Conceptually:
  • Without CloudFront: the browser requests content directly from the S3 object URL in the Region where the bucket lives.
  • With CloudFront: the browser requests content from a CloudFront edge location. CloudFront fetches the object from S3 when needed, caches the response at the edge, and returns it to the user.
We’ll keep this simple and build step by step.

1. Create an S3 bucket and upload a test file

Steps:
  1. Open the Amazon S3 console and create a new bucket. In this demo the bucket is in us-east-2 (Ohio) and named eden-kk-cloud-bkt. Bucket names must be globally unique.
  2. Upload a minimal index.html file that contains a “Hello world” page.
Here is the upload view showing the index.html file ready to be uploaded:
A screenshot of the Amazon S3 upload page for the bucket "eden-kk-cloud-bkt" showing one file (index.html, 23.0 B) listed. The interface shows options like "Add files", "Add folder" and destination settings.
After uploading, try opening the object URL in a browser. By default, a newly created bucket blocks public access, so requesting the object URL returns an Access Denied error:
To demonstrate direct access for this demo only, temporarily allow public reads on the bucket. Two steps:
  • Disable “Block all public access” on the bucket.
  • Add a bucket policy that allows s3:GetObject for all principals for objects in the bucket.
Minimal public-read bucket policy for eden-kk-cloud-bkt:
Once public read is enabled, open the object URL in a browser. The sample page shows “Hello world!” served directly from the S3 object URL:
A browser window showing a minimal webpage with the text "Hello world!" in large bold font on a white background. The address bar indicates the page is served from an Amazon S3 bucket (eden-kk-cloud-bkt.s3.us-east-2.amazonaws.com/index.html).
Note: Serving content directly from a public S3 bucket is simple but not recommended for production due to security and performance reasons.
For production, keep your S3 bucket private. Use CloudFront with Origin Access Control (OAC) so CloudFront can securely fetch objects from S3 on behalf of users without exposing the bucket.

2. Revert the bucket to private (prepare for CloudFront)

Before creating CloudFront, revert the bucket to a secure state:
  1. Re-enable “Block all public access”.
  2. Remove the temporary bucket policy.
After these changes, the S3 console should show that public access is blocked and no bucket policy is present:
A screenshot of the AWS S3 console showing the "eden-kk-cloud-bkt" bucket permissions page with the Bucket policy section. A notice indicates Block Public Access is turned on and public access is blocked.
If you try the direct object URL now: https://eden-kk-cloud-bkt.s3.us-east-2.amazonaws.com/index.html you should get Access Denied. This is the desired state when using CloudFront with OAC. Tip: To quickly verify behavior from the command line:
  • Direct S3 request (expected: Access Denied after locking down bucket):
    • curl -I https://eden-kk-cloud-bkt.s3.us-east-2.amazonaws.com/index.html
  • CloudFront request (after distribution is deployed — see next section):
    • curl -I https://<cloudfront-domain>/index.html

3. Create a CloudFront distribution and configure the S3 origin

Create a CloudFront distribution that uses the S3 bucket as its origin so CloudFront can serve cached content from edge locations while the bucket stays private. Steps:
  1. Open the Amazon CloudFront console and click “Create distribution”.
  2. Choose the appropriate plan and give the distribution a name (for example: CF-eden-KK).
  3. For origin type, select “Amazon S3”.
  4. Browse and select your eden-kk-cloud-bkt bucket.
  5. Choose the AWS-configured Origin Access Control (OAC) / “Allow private S3 bucket access” option. This instructs CloudFront to use an identity with access to the bucket and allows CloudFront to write the appropriate bucket policy.
The CloudFront creation UI indicates CloudFront can write and update the S3 bucket policy for secure access:
A screenshot of the AWS CloudFront console on the "Create distribution" review page showing Origin settings for an S3 origin, including a blue info box that CloudFront can write and update S3 bucket policies. The Cache settings section is partially visible below.
  1. Create the distribution and wait for its status to finish deploying (the console will show a stable status once complete). This usually takes a few minutes.
The CloudFront console lists distributions and their domains once deployed:
A screenshot of the AWS CloudFront console on the Distributions page showing "No distributions" with a prominent "Create distribution" button. The left sidebar lists CloudFront menu items (Distributions, Policies, Functions, etc.) and the top bar shows the account/region.
During creation you may see the plan selection or distribution naming screens:
A screenshot of the AWS CloudFront console on the "Create distribution" page showing the "Choose a plan" step with options like flat-rate and pay-as-you-go and pricing cards (Free, Pro $15/mo). The left sidebar lists the setup steps for creating a distribution.
A screenshot of the AWS CloudFront console showing the "Create distribution" / "Get started" page with the Distribution name field filled as "CF-eden-KK". The left sidebar shows the multi-step setup and the main pane displays distribution options and configuration fields.
CloudFront will create or update an S3 bucket policy granting the CloudFront OAC access to objects in your bucket. This lets CloudFront fetch objects from a private bucket without exposing the bucket to the public internet.

4. Access the site via CloudFront

After the distribution status is deployed, copy the CloudFront domain name (for example dxxxxxxxxxxxx.cloudfront.net) and request the same object via CloudFront: https://<cloudfront-domain>/index.html Because CloudFront is configured to access the private S3 bucket using OAC, CloudFront will fetch the object from S3, cache it at the edge, and deliver it to the user. The S3 bucket itself remains private:
A screenshot of the Amazon S3 console for the bucket "eden-kk-cloud-bkt" showing a blue notice that public access is blocked because Block Public Access settings are turned on. The page also indicates there is no bucket policy to display.
If you try the direct S3 URL now: https://eden-kk-cloud-bkt.s3.us-east-2.amazonaws.com/index.html it still returns Access Denied, but the CloudFront URL serves the content. This demonstrates CloudFront acting as the content delivery layer between users and your origin. Summary of differences: Useful references:

5. Cleanup

Remove resources to avoid ongoing charges:
  1. In CloudFront:
    • Select the distribution, choose “Disable”, wait for it to be disabled, then delete the distribution.
  2. In S3:
    • Delete all objects in the bucket.
    • Remove any bucket policy.
    • Delete the bucket (you will be prompted to type the bucket name to confirm).
The delete bucket confirmation screen looks like this:
A screenshot of the AWS S3 console on the "Delete bucket" page for the bucket named "eden-kk-cloud-bkt". A warning box explains deletion cannot be undone and prompts the user to type the bucket name to confirm.
After deletion you should see a success banner indicating the bucket was removed:
A screenshot of the Amazon S3 console showing a green success banner that says "Successfully deleted bucket 'eden-kk-cloud-bkt'." The page below lists General purpose buckets with controls like Copy ARN, Empty, Delete, and a Create bucket button.
That completes the demo: create an S3 origin, show direct access, secure the bucket, create a CloudFront distribution that serves the same content from the CDN, and clean up afterward.

Watch Video