How to Deploy a Secured Static Website on AWS

Nisha P
13 min readJan 19, 2023

--

In this project, I demonstrate the steps for deploying a secured static website to AWS. We will utilize Amazon S3 bucket storage service to host our website file and Amazon Route 53 will be used to acquire a new custom domain name and for management of DNS. We will secure the website using an SSL certificate and then serve up our content by using a CloudFront distribution for fast delivery!

Pre-requisite: You will need an Amazon Web Services (AWS) Account

Services used: Amazon S3, Amazon Route 53, Certificate Manager (ACM), and CloudFront

Repo for this project: Static Website on AWS

Table of Contents

  1. Purchase a custom domain from AWS Route 53 domain registrar.
  2. Create an Amazon S3 bucket and upload website files to it
  3. Use Route 53 to redirect our custom domain URL to the AWS-provided URL
  4. Request Certificate from ACM
  5. Add Cloudfront Distribution
  6. Update DNS record to point to Cloudfront Distribution

Step 1: Purchase a custom domain from AWS Route 53

Amazon Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service offered by Amazon Web Services (AWS). In addition to DNS services, it provides health-checking services to automatically route end users to healthy application endpoints and supports domain registration services. In this step, we will purchase a domain for our website using the Route 53 service.

From the AWS Console, search for “Route 53” and select it from the resulting list of services.

Search for Route 53 from the list of services

You will be directed to the Route 53 Dashboard. From here, click on “Registered Domains” from the left-side menu.

Route 53 Dashboard

On the next page, you will click on the “Register Domain” button.

Registered Domains page

On this Domain Search page, you will enter your desired domain into the field, select a domain extension from the drop-down list, and then click on “Check” to find out if your domain name is available for purchase.

Domain Search Page

In my example, I’ve selected “nishaproject.click”. I selected the “.click” extension because it is the cheapest one available. Click on “Add to cart”

Choose a domain name

After adding your chosen domain name to the shopping cart, you will be taken to a checkout page where you need to fill out your contact information in order to complete the purchase.

Shopping Cart

Prior to finalizing your purchase, you will need to accept the “Terms and Conditions” of the Route 53 DNS registration services. You also have the option to allow automatic renewal of your domain on an annual basis. It is set to “Enable” by default. However, you can change this setting at any time.

Managing DNS for your New Domain

After submitting your order, you will see a notification that your order has been submitted and will be debited to your payment method on file. Click on Close and then click on the “Go to Domains” button.

Order submitted successfully
Domain Registration Confirmation Page

You will likely be presented with a “Pending requests page”. It took about 10 minutes after completing my purchase before my domain completed the registration process.

Registered domains — Pending requests

Step 2: Create an Amazon S3 Bucket

Amazon S3 (Simple Storage Service) is a cloud-based object storage service offered by Amazon Web Services (AWS) that allows users to store and retrieve data through web-based interfaces and APIs, and can be used for a wide range of storage and archiving needs, such as backup and disaster recovery, big data analytics, and content distribution. S3 provides high durability and availability and allows users to store data in a variety of formats and scales.

You will use an Amazon S3 Bucket to store your website file(s). To begin, search for s3 in the top search bar and select it from the resulting list of services.

Search for S3 from the list of available services

On the next page, click on “Create Bucket”.

Amazon S3

On the “Create bucket” page, enter the following information to configure your S3 bucket:

Bucket name: <your domain name>

AWS Region: Select the region closest to you

Create Bucket — General Configuration

Scroll down to the “Block Public Access settings for this bucket” section below. This will be set to Block public access by default. Uncheck the box to enable public access to the bucket so that it will be publicly accessible for others to view your website. Scroll down further below and select the checkbox to acknowledge the warning about the public access settings.

Public Access Settings

Scroll down to the bottom of the page and click on “Create Bucket”.

Create bucket button

Once the bucket has been created, you will see your domain name reflected as the bucket name. From here, we need to modify some settings of the bucket. Click on your bucket name to navigate to the bucket settings.

Buckets Page

Navigate to the Properties tab and then scroll down to the static website hosting settings.

Bucket Properties page

At the Static website hosting section, click on the “Edit” button.

Modify the Static website hosting settings by making the following changes:

Static website hosting: select Enable

In the “Index document” field, enter “index.html”

Edit Static Website Hosting

Scroll down to the bottom and click on the “Save Changes” button to accept the new settings.

Updated Static website hosting settings

Upload your website file(s)

Navigate back to the “Objects” tab and click on the Upload button.

S3 Bucket Objects tab

Click on Add files and then navigate to the saved location of your index.html website file on your local machine and select it to open it. You also have the option to click on “Add folder” if you need to store additional assets using a folder hierarchy for your website.

Scroll to the bottom of the page below and click on the “Upload” button.

Upload to S3 Bucket

Click on Close.

Upload successful

Create a Bucket Policy

Next, you will create a Bucket Policy for the bucket by modifying its permissions. Navigate to the permissions tab, scroll down to Bucket Policy > Click on Edit.

Edit Bucket Policy

Copy the code listed below and paste it into the Bucket Policy field on the AWS console. Replace the “Bucket-Name” parameter to match the name that you have configured for your S3 Bucket on the AWS Console.

{ 
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::Bucket-Name/*"
]
}
]
}

Scroll to the bottom of the page and click on “Save Changes”.

Bucket Policy

You have now configured the bucket to allow for public accessibility to reach the website. If you go back to your website and click on it, you should see your welcome message if you click on “Open”.

Open website

The welcome message is displayed, but the URL that is utilized is an AWS-provided URL rather than our custom domain. We will need to update the DNS records on Route 53 service to redirect our domain to our S3 Bucket.

Website Welcome Message

Step 3: Redirect the custom domain to the URL of the S3 Bucket website

In this step, we will return to Route 53 services so that we can configure the Hosted Zone to use a DNS record that will redirect from our custom domain to the URL of the S3 Bucket website. In the top search bar, enter Route 53 and select it from the list of services:

Search for Route 53

From the Route 53 Dashboard, click on Hosted Zones.

Route 53 Dashboard

From the Hosted Zones section, Click on your domain name.

Hosted Zones

Click on Create Record.

DNS Records of Hosted Zone

On the Create record page, you will create an alias record for your Apex/root domain so that it will redirect to your S3 Bucket website. You will accomplish this by entering the following information:

Alias: toggle the switch to “on”

  • Route traffic to: Alias to S3 endpoint
  • Region: Choose the Region for your S3 endpoint
  • Enter S3 endpoint: Select your S3 Bucket from the list
  • Routing Policy: Simple Routing

Click on “Create records”

Create DNS A Record for S3 Endpoint

You will then see a confirmation of the successful creation of the DNS record for your domain.

Hosted Zone Details

Test Your Website URL

Navigate to the FQDN of your domain in your web browser and your website should be available once the DNS records have had enough time to complete the propagation process. Congratulations! You have completed the hosting of a static website on an Amazon S3 bucket!

Notice in the browser that the website is indicating that it is unsecured and not trusted by the browser. We can mitigate this by requesting an SSL certificate for our site from a Certificate Authority. Fortunately, AWS offers a service known as Amazon Certificate Manager (ACM) where we can request the issuance of a certificate for our site for free! Let’s do this!

Step 4: Request Certificate from ACM

Amazon Certificate Manager (ACM) is a service provided by Amazon Web Services (AWS) that allows users to easily manage and deploy Secure Sockets Layer/Transport Layer Security (SSL/TLS) certificates. It allows users to provision, manage, and deploy SSL/TLS certificates for use or integration with AWS services, such as Elastic Load Balancing, Amazon CloudFront distributions, and APIs for Amazon API Gateway. ACM also manages the renewal and replacement of certificates automatically. SSL/TLS certificates allow web browsers to identify and establish encrypted network connections to websites using the SSL/TLS protocol.

To request a certificate from ACM, begin by searching for “certificate manager” in the top search bar and selecting it from the resulting list of services. NOTE — Please make sure that you are in the US East Virginia region when you request your certificate.

Search for Certificate Manager

At the AWS Certificate Manager page, click on Request a certificate.

AWS Certificate Manager

Click on the first radio button for “Request a public certificate” and then click on Next.

Request a public certificate

In the “Domain names” section, enter the FQDN for your domain. Scroll down to the “Validation method” section and select an option for validating your domain. DNS validation is the recommended option and I found it quite easy to complete through the AWS console.

Request public certificate

Scroll down to the Key algorithm section and select RSA 2048 for the encryption algorithm. Then, click on the “Request” button below.

Request public certificate — Key algorithm

You will then see a banner appear at the top of the Certificates List page confirming that the certificate request was successful. You should see your certificate issuance in a “Pending validation” state in the list below. If not, click on the refresh button and it should appear momentarily. Then, click on the blue text listed under the “Certificate ID” column.

Certificate Request — Pending validation

You will be taken to an information page related to your certificate request. Here, you will scroll to the Domains section and click on “Create records in Route 53” so that ACM will create the proper CNAME record needed to complete the DNS validation process.

Certificate Request DNS Validation

On the next page, you will tick the checkbox in front of your domain name and then click the “Create Record” button to create the DNS record in Route 53. This will validate your domain ownership so that Route 53 will issue the certificate for your website.

Create DNS records in Amazon Route 53

Once you have completed this process, you will notice that your domain validation status is reflected as “success” and the certificate status is “issued”. This completes the certificate process. However, we now need to create a CloudFront distribution for our website so that we can utilize the certificate because we cannot use the certificate with the S3 resource.

Certificate issued

Step 5: Add Cloudfront Distribution

In step 5, we will create a CloudFront distribution for our website so that we can utilize the certificate for secured access to our website. There are many benefits to using CloudFront with the primary benefit is having the ability to distribute your media through the AWS backbone network to the edge location that can best serve your content to viewers. CloudFront is a Content Delivery Network (CDN) service that provides faster delivery and a low latency experience for those who want to view your website.

To begin this process, you will search for CloudFront in the top menu and select it from the resulting list of services.

Search for Cloudfront

At the Cloudfront landing page, you will click on “Create a CloudFront distribution” button.

Amazon CloudFront

On the next page, click into the “Origin domain” field and select your S3 static site URL.

Create distribution origin

Here, you will be prompted to convert your S3 static site to a website endpoint. Click on this button to complete this conversion process.

CloudFront distribution — Origin domain

Your origin domain name will then change to include “website” in its URL.

Website Endpoint Origin domain

Scroll down to the Default Caching Behavior section and select the following settings below:

Default Caching Behavior
Default caching behavior

Scroll down to the “Custom SSL Certificate” section and select your site’s certificate from the list.

Custom SSL certificate

Scroll down to the bottom and click on “Create Distribution”.

Create distribution

You should see a banner message indicating that your new distribution was successfully created.

Distribution creation successful

Step 6: Update DNS record to point to CloudFront distribution

In this final step, we will update the DNS record to point to the CloudFront distribution. Search for Route 53 in the top search bar and select it from the list of services.

Search for Route 53

From the Route 53 Dashboard, click on Hosted zone.

Route 53 Dashboard

Click on the name of your Hosted Zone, which is your domain name.

Hosted Zones

Click the checkbox on your A record for your domain. In the Edit pane that opens on the right, modify the “Route traffic to” field so that the selected option is now “Alias to CloudFront distribution” and then click on save.

Modify Hosted Zone Records

This completes all of the necessary steps for deploying a secured static website on AWS. I got a little creative with mine after finishing all of these steps and created a simple HTML page that is reflected in the image below. You are free to create your own index.html document or use any HTML website template that you like.

Stay tuned for my next article where I will demonstrate the deployment of a similar website using Azure Cloud services.

Thank you for reading!

http://nishaproject.click

--

--

Nisha P
Nisha P

Responses (2)