Deploying and Hosting Static Websites on AWS Cloud.
Tags: aws, beginners, tutorial, cloud
Published: 2022-07-18 07:08:54

Amazon Web Services (AWS) offers a massive range of services for every business, starting with essential elements, like computing, storage, and network security tools, through complex solutions like blockchain, machine learning, artificial intelligence, and robot development platforms, all the way through very specialized tool sets, like video production management systems, and orbital satellites you can rent by the minute.

This Article is divided into three sections: AWS Free tier Account and required services; S3 Bucket config and Upload; CloudFront deployment settings.

Today, we’ll be deploying a static website to AWS Cloud with:
![The AWS Free-tier account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rt9334l7hprmplml4df.png)


1. [AWS Free-tier Account](https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fportal.aws.amazon.com%2Fbilling%2Fsignup%2Fresume&client_id=signup&code_challenge_method=SHA-256&code_challenge=8-bSETvhqxFdTSt0xuVzkPl9Et8XByKLAWrDfSRIQ-U)
2. A code editor (I used VS Code to write the .html, .css, and .js documents).
The services used in deploying this site are:

Amazon Simple Storage Service(s3): is a service that provides object-level storage. Amazon S3 stores data as objects in buckets. You can upload varying file types to Amazon S3, such as images, videos, text files, etc. On a free tier account, all objects in the s3 bucket have a 99.99 percentage probability that it remains intact after a yearly period.

Amazon CloudFront: This is a global content delivery network that delivers data, video, applications, and APIs to customers around the globe with low latency and high transfer speeds.

STEP 1: CREATE AN S3 BUCKET

The first step is to create an S3 bucket, configure the bucket for website hosting, and secure it using Identity and Access Management (IAM) policies. An IAM policy is a document that allows or denies permissions to AWS services and resources.

Navigate to the “AWS Management Console” page, type “S3” in the “Find Services” box, and then select “S3”. The Amazon S3 dashboard displays. Click “Create bucket ”.


![Accessing s3 from the AWS mgt console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2h0osh7jar2f8rnrp9m.png)

Give the s3 bucket a unique name and select a region. In the Bucket settings for Block Public Access section, uncheck the “Block all public access”, to enable public access to the bucket objects via the S3 object URL.


![uncheck "block all public access"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3x3iuxhlvxq4nrk0tm2j.png)

Click “Next” and click **“Create bucket”**. Once the bucket is created, click on the bucket’s name to open the bucket to the contents.

STEP 2: UPLOAD FILES INTO THE S3 BUCKET

After creating the S3 bucket, the next thing is to upload your files. Once the bucket is open to its contents, click the “Upload” button.

Click the “Add files” and “Add folder” buttons, and upload the files and folder(s) content from your local computer to the S3 bucket. Here, the files may include .html, .css, .js and or other folders.


![The documents become visible once, you upload them](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hct5dsccen5edxt8lqn.png)

Kindly note, that you can upload files and folders to your s3 bucket via the AWS Command Line Interface(CLI), however, ensure, that you have created an IAM User and successfully configured it.

STEP 3: SECURE THE S3 BUCKET

Earlier in step 1, we made the s3 Bucket publicly accessible, now we must secure it. Now we’ll go to the Permissions tab, I can see the bucket allows public access for hosting, to secure it, I’ll create a Bucket policy.

The “Bucket Policy” section shows it is empty. Click on the Edit button. Enter the following bucket policy and replace “your website” with the name of your bucket and click “Save”.


![Edit the bucket policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93psk87cgjx247ham80i.png)


You will see warnings about making your bucket public, but this step is required for static website hosting.

STEP 4: CONFIGURE S3 BUCKET

To configure your s3 Bucket, go to the Properties tab and then scroll down to edit the Static website hosting section. Click on the “Edit” button to see the Edit static website hosting screen. Now, enable the Static website hosting, and provide the default home page and error.

After successfully saving the settings, check the Static website hosting section again under the Properties tab. You must now be able to view the website endpoint as shown below:


![view the s3 endpoint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fr4o7jp6xdhoaxzvy34e.png)

STEP 5: AMAZON CLOUDFRONT

The last step is to distribute the website via CloudFront. Select “Services” from the top left corner and enter “cloud front” in the “Find a service by name or feature” text box and select “CloudFront”. From the CloudFront dashboard, click “Create Distribution”. For “Select a delivery method for your content”, click **“Get Started”**.

To create a distribution;

Origin domain — Do not select the bucket from the dropdown list, paste the hosting endpoint you got from configuring the s3 bucket above.

**Enable Origin Shield — ‘No’
Compress Objects Automatically — ‘Yes’
Viewer protocol — ‘Redirect HTTP to HTTPS’
Restrict Viewer Access — ‘No’
Cache behavior, key and origin requests**

Leave the defaults for the rest of the options, and click “Create Distribution”. It may take up to 10 minutes for the CloudFront Distribution to get created. Once the status of your distribution changes from “In Progress” to “Deployed”, copy the endpoint URL for your CloudFront distribution found in the “Domain Name” column.



![CloudFront Link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3lgdosm63emup123ijom.png)

In this article, the [Domain Name](https://d1uir28avf8ke2.cloudfront.net/) is, but yours will be different.

**Now, you just deployed your static website to the cloud, using the AWS free tier account. Congratulations!**