Log4j Vulnerability Response Center. Get Informed Now

Back to blog results

November 30, 2016 By Michael Floyd

CDN with AWS CloudFront - Tutorial

Consider a situation in which you’ve developed a groundbreaking website, and you would like to share your content with the world. The problem is that your hosting provider is based in New York, and you’re concerned that a user from a different region, such as Europe or Australia, won’t be able to view your content quickly and reliably. AWS CloudFront is a content delivery network (CDN) solution that allows your content distribution to be shared in an accelerated manner from multiple edge locations around the world.

Consider a situation in which you’ve developed a groundbreaking website, and you would like to share your content with the world. The problem is that your hosting provider is based in New York, and you’re concerned that a user from a different region, such as Europe or Australia, won’t be able to view your content quickly and reliably. AWS CloudFront is a content delivery network (CDN) solution that allows your content distribution to be shared in an accelerated manner from multiple edge locations around the world.

What is the Main Benefit of CloudFront?

CloudFront allows businesses to deploy content with low latency and high data transfer speeds. This allows end users to get an immediate response from the website as soon as they search for information.

Is AWS CloudFront Free?

Amazon has an AWS Free Usage Tier, which includes AWS CloudFront. The free tier of Amazon CloudFront includes:

  • Up to 50GB of data transfer
  • 2,000,000 requests per month aggregated across all edge locations
  • Free for 12 months

How Long Does CloudFront Take to Deploy?

CloudFront can take up to 25 minutes to deploy. This is because CloudFront delivers content through a worldwide network of low latency and high performance edge locations. It can take additional time depending on how long it takes to propagate changes in configurations such as certificates, origins, settings and more.

How Long Does it Take to Delete a CloudFront Distribution?

Deleting a CloudFront distribution can take up to 90 minutes to complete. This is because the changes must propagate across all edge locations.

Speed Plus Reliability

When a user’s browser requests an image or other content from your website, chances are that request will bounce around the Internet as many as 10-20 times while it is routed to the correct location to retrieve that content. What CloudFront does is keep a copy of that content available at multiple locations around the world. When a request is received for the content, CloudFront is able to serve it up from the location with the lowest latency for the user, and with a reduced number of hops around the internet.

Having the content available at multiple locations also increases the reliability of the content, because it is available from multiple locations around the globe. At the time of writing, more than 60 Amazon Cloudfront edge locations were available on five continents.

Is CloudFront Faster Than S3?

Yes, CloudFront is faster than S3. CloudFront has lower latencies and loads tens of milliseconds faster, even from non-edge locations..

Setting Up Content You Want to Share in AWS CloudFront

You’ll need access to an AWS environment in order to complete the following. All of this should be available if you are using the free tier. For more information on how to set up a free account, please visit AWS.

For this example, we’ll make an image available from CloudFront. In the past, when you wanted to include an image on your site, you would upload the image and then reference it directly from your page with a link such as


With this example, we’ll upload that image to S3, setup some permissions and then distribute it over CloudFront. The end result will be a URL similar to:


You can include this on your page, and it will allow users to access the image quickly and reliably.

Step 1. Create a New Bucket.

Let’s begin by navigating to your S3 console in AWS. Ensure you are signed into your AWS account. Create a new bucket by clicking on the Create Bucket button.


Select a region close to you and enter a unique name for your bucket which conforms to AWS requirements (http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html), and then click Create.


With your new bucket created, click into the folder, and then click on the Actions button, and choose the Upload action. Drag your image onto the Drag and drop files area of the screen. Before you upload, click on the Set Details > button, and then Set Permissions >. Check the box next to Make everything public, and then click on Start Upload.


You should now have your image available in your bucket. And you should be able to view your image through a browser at your specific URL, which should look similar to


depending on your region and bucket name.


With public content, we’re now ready to create a CloudFront Web Distribution.

Step 2. Create the CloudFront Web Distribution

Ensure you are signed into your AWS account, and navigate to https://console.aws.amazon.com/cloudfront/. Then click on Create Distribution.


Since we’re planning on serving up static web content, we’ll click the Get Started button under the Web section.


You will now be presented with a page full of options. These options control where the content is sourced, how it will be cached and how it will be delivered to your users. I used the default values where possible in order to set up the simplest distribution possible. Clicking on the black information icon to the right of each option will explain what the setting is used for.

Step 3. Select Your Origin Settings

  • Origin Domain Name: This is the URL of the S3 bucket where you stored the image. In my case this will be set to: global-content-images.s3.amazonaws.com.
  • Origin Path: Optional field specifying a subdirectory within the bucket. I left this blank.
  • Origin ID: Description of the origin. This allows you to add a description which allows you to differentiate multiple origins in the same distribution from each other. I left mine set to the default which is: S3-global-content-images
  • Restrict Bucket Access:This option restricts users to using the CloudFront URL only, and prevents access to the resource through the S3 URL. This is set to No by default, which I chose to keep.
  • Origin Custom Headers: These are used to add custom headers to the request from the client. I left these blank.

Step 4. Set the Default Cache Behavior

I’ve accepted the default values for all of this settings. This allows end users to access my resource using both HTTP and HTTPS protocols, and cached the object on the CloudFront edge locations for 24 hours. This also allows open access to my resource and didn’t automatically compress it. For more information on these settings and how you can optimize them to meet your needs, Amazon offers an excellent description here.


Step 5. Enter Your Distribution Settings

As with the Default Cache Behavior Settings, you can simply leave the default values in this section as well. These settings determine how your resource will be distributed, including pricing options, logging options and HTTP and SSL options.

As with all AWS offerings, there are allowances built into the Free Usage Tier if you are using the 1-year free trial offered by Amazon. The pricing structure is based on demand and usage and is explained in greater detail on the pricing page.

Finally, I ensured that the Distribution State was set to Enabled, and clicked Create Distribution.


At this point, AWS will begin processing the distribution. The screen you’ll see lists all CloudFront distributions, and includes a Status column, which will update from In Progress to Deployed when your resource is ready to test. Amazon indicates that the process can take as long as 15 minutes. When I tried this on my account, it seemed to be closer to 20 minutes. Even after the 20 minutes, however, while my distribution was deployed, it still took additional time for the image to become available. I suspect this may be a result of the time required for propagation of the DNS information.


Step 6. Testing Your CloudFront Web Distribution

Once the status of your distribution has changed to Deployed, you can test it. The URL for the resource is made up of the Domain Name assigned in the distribution, and the Object Name of your original resource in S3. In my case, this results in a URL of: http://d2zo62o2iuzu83.cloudfro... where d2zo62o2iuzu83 is the assigned by CloudFront for the distribution.

It’s as Easy as That!

Aside from the additional time you may experience waiting for the image to become available, these steps are all you have to complete to make your content readily available around the world.

SumoLogic and AWS CloudFront

After you’ve setup your instance of CloudFront, you’ll want to try SumoLogic (its free to try!).

With SumoLogic, you get a solution that was purpose-built for CloudFront. SumoLogic allows you to:

  • Analyze visitors and content being served by CloudFront
  • Correlate your CloudFront data with internal data to measure the impact of CloudFront as a CDN
  • Create insights into user activity trails
  • Decrease errors and downtime
  • Troubleshoot and improve quality of service.

Improve performance, user experience, and security

Sumo Logic lets you easily troubleshoot issues and validate the value-add of your CloudFront CDN.

Sumo Logic Continuous Intelligence Platform™

Build, run, and secure modern applications and cloud infrastructures.

Start free trial

Michael Floyd

More posts by Michael Floyd.

People who read this also enjoyed