AWS CloudFront – Basics

Introduction

One of the biggest challenges for websites and web applications is latency. Latency can be managed by reducing the distance between users and the application.

AWS CloudFront is a Global Content Delivery Network (CDN) designed to reduce latency and reduce application load.

CloudFront works by edging contents to locations around the world that are closer to your users.

Request to your application will automatically route to the CloudFront edge location nearest to the requester, ensuring fast delivery of your contents.

CloudFront integrates seamlessly with other AWS such as S3, EC2 and Load Balancers.

CloudFront can edge content called objects from these resources, meaning the requests are resolved by CloudFront instead of requesting the content from your S3 bucket or application.

CloudFront can also act as go-between (proxies) for dynamic contents for your EC2 instances.

CloudFront Distributions

A set of content edged with CloudFront is called a distribution.

A CloudFront distribution is given its own URL on the cloudfron.net domain (e.g. 1234abc.cloudfront.net) which you can use in DNS rules with your own domain.

Each distribution provides content from one or more origins like S3 buckets, EC2 instances or load-balancers.

A distribution has different behaviors dictating how it will edge content.

You can specify a URL path to create different behaviors for different directories or types of content (e.g. determine cache behavior based on path, set timeout for specific content etc.).

Edging Your Application with CloudFront

I have an S3 bucket configured to serve a simple static website and now we will distribute this website using CloudFront. You can check this post, to see how to setup an S3 based static website using AWS CLI.

Simply visit the CloudFront dashboard on web console and start by creating a distribution.

In the Origin Domain Name select the bucket that contains your app, Name will be populated:

As you can see, I’ve selected the S3 bucket for Origin domain. Next, following picture shows option was selected to redirect HTTP calls to HTTPS. That’s cool, as amazon S3 website endpoints do not support HTTPS, and due to CloudFront, we got not only HTTPS but also HTTP to HTTPS redirection easily setup here.

There are many other options and configurations, which you can set as per your need. But for this simple demo, I let the default values for other fields and simply click the Create distribution button. Wait a few minutes until the deployment has finished, and then click on the ID of your distribution.

As you can see that CloudFront gave us a URL and once I visit the URL following information shows up in the browser:

I then entered the index.html to end of URL and the website shows up properly:

We can easily fix that, by editing the distribution and setting the Default root object to index.html as shown below:

Now, users won’t have to type the index.html manually to the URL:

That’s it. Our website is now being delivered by the powerful AWS CDN.

Summary

CloudFront is a Content Delivery Network (CDN) service that will copy your app to edge locations around the world to improve the speed in which your app is served to your users.

In later post, we will cover some other settings offered by CloudFront.

Let me know if you have some comments or questions. Till Next Time.

My Recent Books

1 thought on “AWS CloudFront – Basics”

Comments are closed.