Deploy a website to AWS CloudFront
Published: 2023-04-29 17:05:09

> This article was originally posted to [my personal blog](https://brianmorrison.me/blog) on 01/26/2020.

In this article, I’ll be demonstrating how to configure AWS S3 and AWS CloudFront to host a static website.
## Setting up S3
To start, I’ll need to create an S3 bucket to store the content of the website. S3 is object-based cloud storage hosted in AWS. You can store any kind of file here, but you can also host a website using their built-in Static Site Hosting. Head over to S3 and click Create bucket;
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/55a432ab-e100-444a-8552-9e5750746778-Untitled.png)
You’ll need to name the bucket something that DNS can resolve to. So lowercase characters, periods, dashes, etc. I named this **wordpress-static-site-test** during this. Later in the series, I’ll likely create a new bucket once I uncover any caveats that go along with this process. On the second page of the Create bucket wizard, I unchecked Block all public access and acknowledged the warning that the contents of the bucket will be public. I left everything else as defaults. If you are doing a lot of these, tagging them would be a good way to figure out what’s what for billing or organizational purposes.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/b91b4a52-81a2-4cc2-b136-2e112f0923a8-Untitled.png)![](/img/n/deploy-a-website-to-aws-cloudfront/0a624c34-aef9-4fbb-8f9c-c14d4d42027a-Untitled.png)
Once the bucket is created, click on it to manage it. Then head over to **Properties**, and enable **Static website hosting**. I set the **Index document** to _index.html_ (I have a sample file I’m using for testing). Note the **Endpoint** URL as well since we’ll need to test this shortly.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/b7e08ef5-ce2c-4771-a13b-09ac6e484a4e-Untitled.png)![](/img/n/deploy-a-website-to-aws-cloudfront/06-2020-01-26_8-40-17-1024x58.png)
Now we need to upload the sample _index.html_. On the second page of the wizard, change the dropdown to **Grant public read access to this object**.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/6511b995-6d8c-48ef-bfdf-c6084d0139d3-Untitled.png)![](/img/n/deploy-a-website-to-aws-cloudfront/6ac2bd15-f26b-4722-8094-3111aa0ad11c-Untitled.png)
Now open a browser window and enter in the **Endpoint** URL you noted earlier. You should get the contents of the _index.html_ file you uploaded. If you do, we’re looking good so far.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/cf1ea82d-82ba-4260-9296-839546281bb9-Untitled.png)
## Creating a CloudFront Distribution
Next were going to deploy this site out to CloudFront, AWS’s CDN. If you are unfamiliar with a CDN, it is essentially a network of endpoints all around the world that is used to distribute your content closer to your users. For instance, if someone accesses my website in Europe, they’ll access it from an AWS data center close to them.
So head over to CloudFront and click **Create Distribution**. If you click on the Origin Domain Name, you should see a list of S3 buckets in your account. Select the one we created earlier.
An **Origin** is where the CDN will pull the content from. You can see here that if you wanted to publish an existing website out to a CDN, you’d just need to set the URL here.
Then scroll down to the bottom and set the **Default Root Object** to _index.html._ We’re telling CloudFront that it will be the default object returned to the requestor if there is no other path or filename afterwards.
Finally, click **Create Distribution** at the bottom.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/9db6b3e1-6368-4c35-bb97-7aec5d9b1281-Untitled.png)![](/img/n/deploy-a-website-to-aws-cloudfront/ed342b47-213e-486d-bb80-868290592614-Untitled.png)![](/img/n/deploy-a-website-to-aws-cloudfront/4ae80494-0755-49ab-89f2-3155a7f6c59f-Untitled.png)
You’ll be returned back to the list of CloudFront Distributions and your new Distribution should show a deployment status of _In Progress_. Wait for it to say _Deployed_ before going any further. This process can take up to 10 minutes in my experience.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/94353f3b-4737-4e71-a31e-38127b2c2d1d-Untitled.png)
Once the status is Deployed, click on the Deployment ID to grab the URL. It’s listed under the General tab as **Domain Name**.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/8f97f4a2-aa3f-408a-b5ea-8fe545d08f9e-Untitled.png)
Enter that URL into your browser and you should receive the same web page you did earlier, but it will be coming from CloudFront instead of directly from S3.
![](https://brianmorrison.me/img/n/deploy-a-website-to-aws-cloudfront/f2ce2b27-e676-4112-be55-a6b78b996e15-Untitled.png)
That’s it! You now have a (rather basic) static website hosted in AWS endpoints all over the world! In the next part of this series, I’ll be looking at requesting a certificate with Amazon Certificate Manager and setting a CNAME in the CloudFront distribution so we can use our own URL.