Creating an Amazon CloudFront Distribution for the Static Website

Lab Steps

lock
Logging in to the Amazon Web Services Console
lock
Creating an Amazon S3 Bucket for a Static Website
lock
Creating an Amazon CloudFront Distribution for the Static Website
Need help? Contact our support team

Here you can find the instructions for this specific Lab Step.

If you are ready for a real environment experience please start the Lab. Keep in mind that you'll need to start from the first step.

Introduction

Amazon CloudFront is a global Content Delivery Network (CDN) that delivers data securely and efficiently. CloudFront pulls your website out to the edge of the network, reducing latency when accessed from different global locations.

In this lab step, you will set up an Amazon CloudFront distribution for your static site hosted in your Amazon S3 bucket.

 

Instructions

1. In the AWS Management Console search bar, enter CloudFront, and click the CloudFront result under Services:

alt

The Amazon CloudFront console will load.

 

2. To start creating a distribution, click Create a CloudFront Distribution:

alt

 

3. Under Origin, in the Origin Domain text-box, enter the Amazon S3 static website hosting endpoint that you created earlier:

alt

Warning: If you don't see the S3 bucket in the origins list, manually enter the following: <name_of_the_bucket>.s3.amazonaws.com

 

 

4. Under Origin, in the Origin access, select Origin access control settings and click Create control setting:

alt

Under Create control setting, enter the following values:

  • Name: Enter
  • Signing behavior: Ensure Sign requests is selected

alt

Origin access control secures S3 origins by allowing access to only designated distributions. This follows AWS best practice of using IAM service principals to authenticate with S3 origins.

 

5. Click Create

Leave all other fields in this section as well as the Default cache behavior section as their default values.

 

6. Scroll down to Settings, and in the Price class selection, select Use only North America and Europe:

Amazon CloudFront minimizes end-user latency by delivering content from its entire global network of edge locations. Price Classes let you reduce your delivery prices by excluding Amazon CloudFront’s more expensive edge locations from your Amazon CloudFront distribution. In these cases, Amazon CloudFront will deliver your content from edge locations within the locations in the price class you selected and charge you the data transfer and request pricing from the actual location where the content was delivered.

The time required for deploying a new CloudFront distribution also depends on the number of selected Edge Locations. Selecting all edge locations will take longer to deploy.

 

7. In the Default root object field, enter index.html.

CloudFront will serve the default root object when the base distribution URL is requested.

You are setting this field because Amazon CloudFront doesn't always transparently relay requests to the origin. If you did not set a default root object on the distribution you would see an AccessDenied error when you access the CloudFront distribution's domain later in this lab step.

To learn more, see the How CloudFront Works if You Don't Define a Root Object section of the AWS developer guide for Specifying a Default Root Object.

 

8. To finish configuring your distribution, at the bottom of the page, click Create distribution:

alt

You will be brought to the distribution details page.

CloudFront automatically assigns an ID (top of the page) and a Distribution domain name to the distribution and starts updating the edge locations to serve your content:

alt

 

9. Return to the Distributions table by clicking the breadcrumb link at the top of the page:

alt

Within the table, observe the Status field of your distribution. It will read Enabled while the Last modified field will display Deploying

It can take up to 15 minutes to deploy a new Amazon CloudFront distribution. Once complete, the Status will change to Enabled.

There are two main types of origin that Amazon CloudFront supports, Amazon S3 buckets, and custom origins. A custom origin could be a website being served by an EC2 instance, or it could be a web server outside of AWS. To learn more while your CloudFront distribution is deploying, visit the AWS Using Amazon S3 Origins, MediaPackage Channels, and Custom Origins for Web Distributions page. 

Once your deployment is complete, continue with the instructions.

 

10. To view details of your distribution, click the random alphanumeric ID:

alt

Note: Your ID will be different.

alt

 

11. Copy the value of the Distribution Domain Name field:

alt

Note: Yours will be different. This domain name is randomly generated and unique for each distribution in Amazon CloudFront.

 

12. Paste the domain name into the address bar of a new browser tab.

You will see the website that you uploaded to your Amazon S3 bucket display:

alt

You are accessing the website through your Amazon CloudFront distribution.

Note: The instructions below are optional. Perform them if there is enough time left in the lab.

 

13. On the website, click through and visit the different pages a few times to generate traffic.

If you have a different web browser available, try accessing the site in the other browser.

 

Summary

In this lab, you created an Amazon S3 bucket and used it to host a static website. You created an Amazon CloudFront distribution and configured it to use your S3 bucket as an origin. You tested that you could access the static website directly through Amazon S3, and through your Amazon CloudFront distribution.

Validation checks
1Checks
Created CloudFront Distribution that Points to Static Website

A CloudFront distribution returns a status code of 200 when visited

Amazon CloudFrontAmazon S3