Configuring a Static Website With S3 & Cloudfront Explained
Tags: aws, webdev, beginners, tutorial
Published: 2022-10-09 14:15:18

---
title: Configuring a Static Website With S3 & Cloudfront Explained
published: true
tags: 
canonical_url: https://makendran.hashnode.dev/configuring-a-static-website-with-s3-cloudfront-explained
---

# Introduction

You can use Amazon Web Services (AWS) to easily and inexpensively host websites that use client-side technologies (such as HTML, CSS, and JavaScript) and do not require server-side technologies (such as PHP and ASP .NET). This type of website is called a `static website` and is often used to display content that does not change.

You can use `Amazon Simple Storage (S3)` to host a static website that is secure, fast, and scalable to prevent data loss and support enterprise traffic. To do this, store your site files in Amazon S3 and use S3 to serve content to to our site visitors. After setting up a static website in S3, you can create a content delivery network (CDN) using `Amazon CloudFront`.

A CDN makes website content available in data centers around the world, called **edge locations**. Edge locations can help speed up your site by reducing latency. This is especially important if your website displays large media files, such as high-resolution images, audio or video.

Are you ready to start?

After following the instructions, your environment should look like this:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663800139352/0ySKEUEan.png)

# Create an Amazon S3 bucket for your static site

**Amazon Simple Storage Service** (Amazon S3) is an AWS object storage service. It is known for its scalability, availability, security and performance features. Object storage is a common need, and Amazon S3 is often part of every non-critical solution built into AWS.

You can create an S3 bucket using the AWS Management Console. As with many other AWS services, you can use the AWS API or the Command Line Interface (CLI). Once the bucket is created, configure it for a static website.

Kindly watch the below video to create an Amazon S3 bucket for your static site



{% youtube tkEpYMdZnGE %}

**NOTE**

- To get a bucket policy that allows public access to all objects in your S3 bucket, click **[here](https://github.com/MakendranG/Youtube/blob/main/Video%201/AWS%20Bucket%20Policy)** and replace `YOUR_BUCKET_NAME` with the name of your S3 bucket.

- To download a zip file containing a basic website, click **[here](https://drive.google.com/drive/folders/1_3oU5rnQbcUQtsdnWsxYL96afJLCUjna?usp=sharing)**.

Paste the endpoint into the address bar of the new browser tab. You should see the site load like this:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663797010558/YaHGAWQWg.png)

This website is powered by an Amazon S3 bucket.

Till now, you created an Amazon S3 bucket, configured it to host a static website, and created a bucket policy. Finally, you uploaded a simple example website and made it publicly available in a web browser.

AWS does not recommend serving websites directly from Amazon S3. Instead, we recommend using Amazon S3 as your content delivery network (CDN) origin. A CDN takes a copy of your website from its original location and stores it in multiple global locations. The main benefit of using a CDN is low latency when users access your site.

# Creating an Amazon CloudFront distribution for your static site

Now, you will create an Amazon CloudFront distribution to place your website behind a CDN.

`Amazon CloudFront` is a global content delivery network (CDN) that delivers data securely and efficiently. CloudFront brings your site to the edge of the network, reducing latency when accessed from a variety of global locations. You configure an Amazon CloudFront distribution for a static site hosted in an Amazon S3 bucket.

Kindly watch the below video to create an Amazon CloudFront distribution for your static site


{% youtube S2m28ciMAc0 %}

- Copy the value in the Distribution Domain Name field.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663801184553/nOcDTPpif.png)

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

- Paste the domain name into the address bar of the new browser tab. The website you uploaded to your Amazon S3 bucket is displayed.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663797010558/YaHGAWQWg.png)

- You access your website through an Amazon CloudFront distribution.

- Drive traffic to your website by visiting and clicking on different pages.

- If you use a different web browser, visit the site in a different browser. 

# Conclusion

Here, 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 an S3 bucket as a source. You have verified that we can directly access our static website through Amazon S3 and Amazon CloudFront distributions.

Gratitude for perusing my article till the end. I hope you realized something unique today. If you enjoyed this article then please share it with your buddies and if you have suggestions or thoughts to share with me then please write in the comment box.

Follow me and share your thoughts,
[GitHub](https://github.com/MakendranG)
[LinkedIn](https://www.linkedin.com/in/makendran/)
[Twitter](https://twitter.com/MakendranG)