The quickest way to create a custom domain name for AWS EC2 instances
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.
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.
Make sure you allow HTTP access from your browser in the security group of the instance.
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.
This should take you into the terminal of the machine, from your browser itself. Isn’t AWS awesome?!
Let us now install Apache and start the service. Just type in the following two commands:
- sudo yum -y install httpd
- 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.
3. Create a new A-record in this domain name.
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!
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!