How to Create an AWS CloudFront Distribution with S3 Origin

How to Create an AWS CloudFront Distribution with S3 Origin

AWS CloudFront is a CDN service. It is a really fast and secure way for low latency content distribution. Cloudfront uses edge locations to enable the user to access content from a website, without traveling all the way to the origin, which results in lower latency.

Why S3 though? For starters, it’s easy to set up and use. It is low cost. A major advantage of S3 buckets is that they are automatically scaled so you don’t need to worry about the space your data might take beforehand.

Setting up AWS CloudFront

Step 1:
Creating an S3 bucket

We’ll be using S3 buckets to store the data. If you already have one you can simply skip to the next step. Else, sign in to your AWS management console and click on S3 under

services to create an S3 bucket. Upload a test image file in that bucket. Then go to permissions and make it accessible to the public.

Step 2:
Creating CloudFront

Under AWS Services find CloudFront and click on Create Distribution.

Step 3:
Creating distribution

Go through the following instructions and enter the required details:

  • Select your S3 bucket in Origin Domain Name (your bucket name).
  • Then provide the path of the folder containing your file next to Origin Path.
  • Then select Create a new identity under Origin Access Identity and Yes, update bucket policy under Grant Read Permissions on Bucket.

Proceed to Default Cache Behavior Settings.

Just make sure to select Redirect HTTP to HTTPS under Viewer Protocol Policy to make sure users don’t get an error when they try accessing your site using HTTP. You can leave the rest of the settings unchanged.

Follow these steps if you want to use a custom domain:

  1. Click on Add item and enter the domain name.
  2. To assign a custom SSL certificate you’ll have to choose the custom SSL certificate you wish to assign from the dropdown list and then create a distribution.

Click on Create Distribution to create your CloudFront distribution. You’ll see the following screen.

You can see the distribution you just created by clicking on Distributions in the left panel. It might not have been deployed yet though. It is completely normal for your distribution to take 10-20 mins to get deployed.

You can change the geo-restrictions, invalidations, etc by going to the distribution settings. Just select your distribution and click on Distribution Settings.

Now go to your distribution’s General tab and try accessing the same file using the CloudFront URL. You can just paste the Domain Name followed by the file’s name in your browser. The result you see now is coming through the CloudFront distribution. It might take a little time to load the file for the first time because the edge location is retrieving the file from the origin for the first time. The second time however it’ll take literally no time.

Conclusion

Please remember to disable and delete the distribution we just created or you’ll end up being charged for it. Also, make sure to read the AWS documentation on CloudFront to get a better understanding of the service and its pricing.

CloudFront can improve the performance of your website in locations far from your origin without increasing the cost exponentially. It’s more economical than sharing your content directly from an S3 bucket. We hope to have helped you set up an AWS Cloudfront distribution by this article.

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How To Set up a VSFTPD Server on an Ubuntu 16.04 VPS or Dedicated Server

Brief Description FTP data is usually insecure since information (usernames, pa
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to use phpMyAdmin to develop a website (without MySQL experience)

Brief description A web developer who is not well versed into coding websites f
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top