DEV Community

Oluwademilade Oyekanmi
Oluwademilade Oyekanmi

Posted on

Deploying a Static Website on AWS

Static websites have predetermined content and can be created without the use of programming languages. It is built with HTML, CSS, and JavaScript and is the simplest type of website to develop. It consists of a number of HTML files, each of which represents a certain internet page physically.

I've outlined below a step-by-step approach for deploying a static website using AWS, leveraging S3 Bucket and CloudFront.

I'll be breaking this into six steps.

  1. Creating the S3 bucket.
  2. Uploading the files to the created S3 bucket.
  3. Securing the bucket using IAM (Identity and Access Management).
  4. Configuring the S3 bucket.
  5. Distribute website using AWS CloudFront.
  6. Accessing website in web browser.

Creating the S3 Bucket

Step 1: In the "Find Services" box, enter "S3," click it, and then select "Create Bucket."

Image description

Step 2: Your bucket name must be distinct for the name. It is suggested that you incorporate your 12-digit AWS account ID into the name of your bucket. Your bucket's name can be my-123456789012-bucket if your AWS account ID is 123456789012.

Image description

Step 3: In the "Bucket options for Block Public Access section," uncheck "Block all public access." The public will be able to access the bucket objects by using the S3 object URL. Which, in my opinion, is the main goal of having a website hosted in the first place.

Image description

Step 4: To create your S3 bucket, click "Next" and then "Create Bucket."

Uploading the Files to the Newly Created S3 Bucket.

Step 1: Open the bucket and click on the 'Upload' button

Image description

Step 2: To upload the files and folders of the website you wish to host from your local computer to the S3 bucket, click the "Add files" and "Add folder" buttons.

Image description

Step 3: Click "Upload"

Image description

You should see this page after that.

Image description

Then,

Image description

Lastly,

Image description

Securing the bucket using IAM (Identity and Access Management).

Step 1: Open your S3 bucket and select the "Permissions" option.

Image description

Step 2: Click "Edit" after scrolling down to "Bucket policy."

Image description

Step 3: Enter the bucket policy listed below, which is written in the code block below. Keep in mind that you are substituting "my-123456789012-bucket" with the name of your bucket.

{
"Version":"2012-10-17",
"Statement":[
 {
   "Sid":"AddPerm",
   "Effect":"Allow",
   "Principal": "*",
   "Action":["s3:GetObject"],
   "Resource":["arn:aws:s3:::my-123456789012-bucket/*"]
 }
]
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Click "Save changes"

Configuring the S3 Bucket.

Step 1: Scroll down to the "Static website hosting" section of the "Properties" tab to make changes. It was the last item on the list as of the time of this documentation. When you do, select "Edit."

Image description

Step 2: Enable hosting for static websites, then provide the name of your index and error document. Next, select "Save changes."
Image description

Step 3: For later usage, make a copy of the "Bucket website endpoint."

Image description

Using AWS CloudFront, Distribute Website.

Step 1: In the text field labelled "Search for service, features, blogs, docs, and more", type "CloudFront."

Image description

Step 2: Click "Create a CloudFront Distribution"

Image description

Step 3: You now need to select the "Origin domain." NOTE: Don't make a selection from the drop-down menu. Instead, substitute the endpoint for hosting static websites in the format "[bucket-name].s3-website-region.amazonaws.com."

Image description

Step 4: Click "Create Distribution" after changing the "Viewer protocol policy" to "Redirect HTTP to HTTPS."

Image description

Accessing Website in Web Browser.

Your CloudFront domain name, S3 object URL, and bucket website-endpoint should all display the same index.html content as confirmation that you followed the correct procedure.

1. CloudFront domain name

Image description

2. S3 object URL

Image description

3. Bucket website-endpoint

Image description

Top comments (0)