Host a Static website on EC2 using Route 53 with 3rd party domain

Raj Parmar
5 min readOct 10, 2021

--

In this blog, I will share my hands-on experience with route 53. I have created a static website that displays Indian Standard Time which I have hosted on a 3rd party domain that is basically free of cost .so in this blog you will learn how to we can create a free domain and connect with AWS services.

AWS Services Used:

  1. EC2
  2. ELB & ASG
  3. Route 53

Here is an architecture diagram for better understanding.

Creating Zip file

The folder which contains website files including index.html is to be zipped and uploaded to the s3 bucket. so our first task is to zip the website folder

Now we will zip our website folder and upload it to s3 bucket

Uploading files to S3

  1. Go to S3 Console
  2. Create Bucket ( give it any name and the rest of it as it is)
  3. Click on the bucket which we have created => Click on upload => Click on Add files => choose zip file => Click on upload

Output:

Creating Auto Scaling Group

  1. Go to EC2 Console
  2. Click on ‘Auto Scaling Groups’
  3. Click on ‘Create Auto Scaling Group’
  4. Give any name to ASG and right click on ‘create a launch template’ and open in new tab
  5. Enter details below:
(select existing key pair or create new key pair)
select security group having inbound SSH and HTTP rules - if don't have then create one

keep rest of the values default and go down to Advanced details

Go to IAM instance profile => Create new IAM Profile [open in new tab]

In the newly opened tab

Click on create role => Select EC2 and click on next => Go to search and type s3 => Press Enter => Select AmazonS3FullAccess => Click Next => Give tags if you want => Click Next => Role name: RoleForEC2 => Click on Create role and close that wondow

Now Come back to create template tab

Go to IAM Instance profile and click on refresh icon and select our new role:RoleForEC2

Leave all other value as it is and

Go to last option user data and paste this script

#!/bin/bash
# Use this for your user data (script from top to bottom)
# install httpd (Linux 2 version)
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
cd /var/www/html
aws s3 cp s3://whatistime/website.zip /var/www/html/
unzip website.zip
mv website/* .
service httpd start

note : whichever in the bold letters my differ in your case so change accordingly

and click on Create Launch Template

6. Come back to Auto Scaling Group tab and click on refresh icon in Launch Template section and select

Click on next

7. Select vpc and all subnets rest of value as it is

Click on next

8. Select ‘attach to a new load balancer’

Select internet facing

Scroll down and go to Listener and routing and select Create a new target group

Set other values as it is and click on next

9. Set these values

Click on next

10. Click on Next

11. Click on Next

12. Click on ‘Create auto scaling group’

Our instance is created with 1 desired capacity now we can go to our website using public IP of our instance

Domain Register

Now we want to register a domain

In my case I have created a website which displays current time so I will register my domain as whatsthetime.ml

I am using freenom because it provides free domain names for everyone

  1. Go to website and sign in[create an account if you don't have]
  2. Click on services => register a new domain
  3. Enter domain name want and click on check availability

Click on get it now which ever domain you want and click on checkout

4. Click continue = > click complete order

Now your domain name is registered successfully

Connect domain with Route 53

Now it’s time to connect our instances with our domain.

  1. Go to route 53 and click on create hosted zones

2. Enter your domain name

Click on create hosted zones

After creating there will be NS record copy it in notepad

3. Go to freenom.com

Go to services => my domains

Click on manage domain

4. Go to management tools => nameservers

Click on Use custom nameservers and paste all 4 nameservers which we have copied earlier in notepad

Click on change nameservers and close the tab

Route 53

Now we are in final step

Click on create record in our route 53 tab

Enter values:
Record name: www
Record type : A
Turn on alias and choose as below

Choose load balancer which we have created using ASG and click on create record

It’s done . Enter your domain name in new tab and it works!!!

Thanks for reading :)

My LinkedIn Profile: https://www.linkedin.com/in/raj-parmar-8a6a6b195/

--

--

No responses yet