The quickest way to create a custom domain name for AWS EC2 instances

Vishakhavel
3 min readNov 28, 2021
Three super simple steps to assign a public domain name for your AWS virtual machines.

Ever wanted to show off in your project reviews by being able to hit your rather mediocre ReactJS application with a custom public domain name? Well, I know I did — so I’m here to share this quick tip with you guys too!

1. You’ll need to have already purchased a custom domain name.

I have purchased mine from AWS Route 53, but you can use any other Domain Registrar to purchase yours, like - GoDaddy or Azure DNS

Having already purchased a domain name from Route 53, AWS will create a public-hosted zone for me automatically.

2. Create an EC2 instance

I will create a simple Amazon Linux-2 t2.micro instance, just for this demo. To test the working of this instance, I will also install the Apache web server, just to show that the instance is up and is reachable from my browser.

I have started the EC2 instance, it has a public IP address 34.220.172.215

Make sure you allow HTTP access from your browser in the security group of the instance.

HTTP access is allowed only from my machine in this rule, but you can also allow HTTP from 0.0.0.0/0 (anywhere)

SSH into this instance using the EC2-instance connect or the terminal (Putty for Windows laptops), and install Apache in the instance. I would strongly recommend the browser-based EC2 instance connect because there is no need to scramble for the “.pem” file to access the machine via terminal.

To connect via EC2 instance connect, simply click on “Connect” on the EC2 dashboard after selecting the instance you just created.

Click on “Connect”

This should take you into the terminal of the machine, from your browser itself. Isn’t AWS awesome?!

You should now be seeing something like this

Let us now install Apache and start the service. Just type in the following two commands:

  1. sudo yum -y install httpd
  2. sudo service httpd start

This should result in Apache downloading and starting in your instance. This can be verified by typing in the public IP of your EC2 instance in the browser.

Hitting the public IP of my instance in my browser results in the Apache test page. So, Apache is installed and the service is running!

3. Create a new A-record in this domain name.

These are a few of the records I have already set up for my portfolio, so ignore these and click on “Create record”
I have typed in “demo” as my record name for this domain name. This means that instead of “www”, I have used “demo” to redirect to my Ec2 instance. You can choose any other name you like, but make sure to follow the guidelines from the valid character set.

It is super important that you choose the type as “A” and not anything else because A is the AWS record type for redirection to IPv4 addresses, and here we are using IPv4 to talk with our EC2 instance.

Once this is selected, click on “Create records” and we’re done!

Typing in “demo.vishakhavel.com” now redirects me to our EC2 instance

Within seconds, AWS Route 53 will have set up everything for us and we can type in the custom domain name into the browser and hit our EC2 instance.

We can see the power of an Authoritative DNS, where the networking and other complex and tedious stuff is handled completely by AWS Route 53.

For more AWS quick tips and tricks, make sure you follow me in medium!

--

--

Vishakhavel

SDE Capillary | ex - Cloud Solutions @ Sony Research India | Certified AWS Developer Associate