- 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.
1. Create an S3 bucket and upload a test file
Steps:- Open the Amazon S3 console and create a new bucket. In this demo the bucket is in
us-east-2(Ohio) and namededen-kk-cloud-bkt. Bucket names must be globally unique. - Upload a minimal
index.htmlfile that contains a “Hello world” page.
index.html file ready to be uploaded:

- Disable “Block all public access” on the bucket.
- Add a bucket policy that allows
s3:GetObjectfor all principals for objects in the bucket.
eden-kk-cloud-bkt:

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:- Re-enable “Block all public access”.
- Remove the temporary bucket policy.

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:- Open the Amazon CloudFront console and click “Create distribution”.
- Choose the appropriate plan and give the distribution a name (for example:
CF-eden-KK). - For origin type, select “Amazon S3”.
- Browse and select your
eden-kk-cloud-bktbucket. - 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.

- 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.



4. Access the site via CloudFront
After the distribution status is deployed, copy the CloudFront domain name (for exampledxxxxxxxxxxxx.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:

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:- In CloudFront:
- Select the distribution, choose “Disable”, wait for it to be disabled, then delete the distribution.
- 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).

