AWS, Cloud Computing

5 Mins Read

A Demo on AWS CloudFront Distribution Using Amazon S3 Origin

Introduction

Amazon CloudFront is a content delivery network (CDN) service that Amazon Web Services (AWS) provides.

It helps businesses and developers deliver their website or application content to users worldwide with low latency and high data transfer speeds.

Amazon CloudFront stores and caches content in data centers located around the globe, allowing it to deliver content to users from the nearest location quickly. This reduces the time and cost of providing content over long distances, resulting in a better user experience and increased performance.

As you may know, a CDN, or content delivery network, is what CloudFront is. It can hasten the dissemination of static or dynamic web content to your users. Examples include HTML, CSS, images, JavaScript, and more.

You must specify the location of the file before Amazon CloudFront can quickly deliver it to your users, and that is the concept behind the origin.

Any HTTP server, including your Amazon EC2 instance, application load balancer (ALB), S3 static website, etc., can be the origin.

If your bucket is not set up as a static website and you wish to deliver your bucket content normally, you utilize s3 origin. You enter bucket-name.s3.regionname.amazonaws.com as the origin domain when building the distribution. But if you want to use Amazon S3, your origin domain would be bucket-name.S3-website.ap-south-1.amazonaws.com.

When using Amazon S3 origin, you have two options: either keep your bucket public so that your users can access it via an Amazon CloudFront URL, or you may keep the bucket private and configure OAI or OAC.

A Demo to Create AWS CloudFront Distribution with Amazon S3 Origin

Step 1: Create an Amazon S3 Bucket

Open the AWS Management Console and log in. Use the Amazon S3 service search box or the Services -> Storage -> Choose Amazon S3.

After entering the Amazon S3 dashboard, select Create Bucket.

Choose a region for your Amazon S3 bucket’s location and give it a distinctive name.

step1

Click Create bucket after keeping the other settings at their defaults.

Step 2: Upload a Few Files into Amazon S3 Bucket

Navigate into your bucket by clicking the name of the bucket.

Click Upload -> Add files from within your bucket to add files.

Click Upload after selecting your file.

In the bucket, I’ve added the file diagram.png. Later, we’ll attempt to use Amazon CloudFront to access diagram.png.

Step 3: Make Your Bucket Public

The newly created bucket is now private. Let’s make it public.

Click Edit under the Block public access (bucket settings) section by selecting the permissions tab.

Uncheck Block all public access and then click Save Modifications as shown below.

step3

Confirm should be typed into the box, then clicked.

This was the initial action. To make this bucket public, add a bucket policy next.

When you reach the Bucket policy section, scroll down and select Edit while still in the permissions tab.

Enter a bucket policy similar to this:

step3b

Then select Save Changes. Your bucket has just become public. If you use a different bucket name, it is important to alter the ARN, which currently reads arn:aws:s3:::cloudfront-demo-ck. Make the resource’s ARN look like this: arn:aws:s3:::bucket-name.

Now, if you look at the permissions page, you will see that bucket access is public. Therefore, anyone can now access your things.

Try serving it from Amazon CloudFront.

Step 4: Create an Amazon CloudFront Distribution with Amazon S3 Origin

To access the Amazon CloudFront service, perform a search.

To create an Amazon CloudFront distribution, click the button in the screenshot below.

Choose your origin file server from the Origin domain in our instance Amazon S3. If you click in the box, you will see several options, including a list of your Amazon S3 bucket. Pick a name for your bucket.

step4

All of my buckets are mentioned in the Amazon S3 origin type, as you can see. The cloudfront-demo-ck bucket is what I’ve chosen.

Take note of the path name, which is cloudfront-demo-ck.s3.ap-south-1.amazonaws.com.

Keep the origin path empty.

step4b

For Amazon CloudFront to be able to access your bucket, as we previously covered, either your bucket must be public, or OAC must be configured so that only Amazon CloudFront can access it:

Note: OAC is usually suggested. However, we are choosing a public bucket for this blog’s simplicity.

Leave everything else at its default setting and click on Create the distribution by scrolling down.

It was successful in creating your distribution. It takes some time to get up and become operational.

step4c

Step 5: Validate Accessing Your Files via Amazon CloudFront

Keep in mind that we stored diagram.png in our bucket.

The URL https://CloudFront-Domain>/file-name> is in your browser, which is at https://d2qsf4u4m24m41.cloudfront.net/diagram.png. The diagram.png appears in the browser as expected.

step5

As a result, your Amazon CloudFront distribution with Amazon S3 origin has been successfully configured.

You will see an error similar to the one below if your S3 bucket is not public or CloudFront does not have access to the Amazon S3 bucket via OAI or OAC.

step5b

AccessDenied is returned by your Amazon CloudFront distribution, as seen in the screenshot. The situation will be great for you if you fix the permission problem.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Conclusion

We talked about the Amazon CloudFront distribution and the numerous origin servers that it supports in this blog. Later, we learned how to use Amazon S3 as the origin for an AWS CloudFront distribution.

We verified a file’s access using Amazon CloudFront after uploading it to an Amazon S3 bucket. We also witnessed the results of denying Amazon CloudFront access to your bucket.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding Amazon CloudFront and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

FAQs

1. What improved performance does Amazon CloudFront offer?

ANS: – To cache copies of your content close to your viewers, Amazon CloudFront uses a worldwide network of edge locations and regional edge caches. The closest edge site will fulfill end-user requests thanks to Amazon CloudFront. As a result, viewer requests are processed quickly, enhancing your viewers’ experience. Amazon CloudFront maintains persistent connections with your origin servers for files not cached at the edge locations and the regional edge caches, allowing for the fastest possible download of such files from the origin servers. Finally, Amazon CloudFront uses other optimizations, such as a wider TCP initial congestion window, to quickly deliver your content to viewers.

2. What distinguishes Amazon CloudFront from Amazon S3?

ANS: – Frequently accessed static content that benefits from edge delivery, such as popular website photos, videos, media files, or software downloads, can be distributed effectively using Amazon CloudFront.

WRITTEN BY Huda Khan

Huda is working as the Front-end Developer in Cloudthat Technologies. She is experienced in building and maintaining responsive websites. She is keen on learning about new and emerging technologies. In addition to her technical skills, she is a highly motivated and dedicated professional, committed to delivering high quality work.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!