Creating a Distribution in AWS CloudFront

posted in: AWS | 0

This is first in a series of posts about CloudFront we will be started with CloudFront By creating our first Distribution.

Overview

Cloud Front is a CDN that allows you to speed your site up no matter where your site is hosted.

it also has some extra features such as geo-restriction that mean it won’t allow someone on the site if they are in a certain country that you have specified to be restricted.

As mention before it can be used to speed up your site by caching(saving) images and other static content to Amazon’s “edge locations”. They have far more edge locations than regions this is to allow the quickest latency for static content, this makes it so the most used objects(files) are very quick to download to the user’s machine as this is physically closer to them. It should also make your web server less busy serving content.

If you want to learn more about AWS CloudFront click here

Disclaimer: if you are not using a free tier account this will cost some money.

Right let’s get started, what you will need:

  • An AWS account
  • A WordPress site to test.
  • Access to your DNS provider

Creating the Distribution

First of all, we go to cloud front an create a “distribution”

We do this by logging into the AWS Console.

Once logged in we can go to CloudFront

Note: Do not use the www. or your zone apex (root domain such as example.com) as your origin, if your server is already using your root domain you may need to move it as this will cause problems with DNS. Don’t worry if are using the root domain or www. I will cover how to deal with DNS in another tutorial.

AWS will autofill most of the form most of the parts are quick self-explanatory view protocol policy is how the client(web browser) connects to clout front. Allowed HTTP Methods are blocking requests of certain types if you are putting a full website behind CloudFront you probably want GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE as this will give the same feeling as being on the original, if your website hasn’t got any forms you may able to get away with GET, HEAD.

We change these two to keep any cookies or query strings (www.exaple.com/?h=test) that may be used on your site

This is why I said that we need www. free as CloudFront will be in front (no pun intended)of the website.

If you don’t it’s not a big deal all we need to do is change the DNS of www. point to CloudFront and maybe make a new DNS entry such as origin.example.com pointing to your web server. Will also need to make sure that CloudFront is pointing to the correct web server. this is out of the scope of this tutorial though, I will cover it if needed.

This can be left bank if you are happy to use something like https://123456789.cloudfront.net/ you may want this if you are using cloud front to cache images for your site (also out of scope)

 

We can leave the rest as default. Click Create Distribution!

There you have it the distribution is in process of getting created, you will probably want to grab a coffee while this is creating.

You can view all the options once this has been created. most of the settings we have set already can be changed.

We will get into these options in later tutorials

Note: Bear in mind when you make changes it may make your site unaccessilbe for a short period so take care. My experience is that CloudFront tries to stay online with minimal downtime but its worth noting!

There we have it, we have created our first CloudFront distribution in the next tutorial we will look into some of the more advance features that cloudfront has to offer.