How to integrate 3rd party Domain Names with AWS Route 53 for your website/webapp

Olutunmbi Banto
Webtips
Published in
7 min readOct 30, 2021

--

Introduction

When you type hellotunmbi.com or any website address in the browser, you are almost immediately taken to the website. What happens within that few seconds is that your request goes through the name servers of the website so as to locate the IP address which is then sent to your computer. This IP address is then used to locate the resource where the website or web application is located. This system is known as the DNS otherwise called Domain Name System.

You can have different applications on separate servers and configure which sub domain accesses which application. For example, hellotunmbi.com can access the server where my website is located while blog.hellotunmbi.com will access a separate server where my blog is hosted. Also, visiting app.hellotunmi.com can serve a different application based on location of the visitor.

In this article, I’ll explain in details:

  • What Route 53 does, how it works and explain various DNS concepts
  • Show you how to setup an EC2 instance, install Apache webserver and host your application on it. You can setup multiple instances if you so wish.
  • Show you how to create and route different records to different services.

Let’s go!

What is AWS Route 53

Route 53 is an “Managed” DNS (Domain Name System). It enables you manage all your DNS records by connecting your public or private domain names with various services.

DNS is a acollection of rules and records which helps clients understand how to reach a server through its domain name.

The 4 common DNS records on AWS Route 53 are:

  • A record: This maps a hostname to an IPv4 address
  • AAAA record: This maps a hostname to an IPv6 address
  • CNAME record: This maps a hostname to another hostname
  • Alias record: Maps a hostname to an AWS resource

Note that a Domain Registrar is not a DNS. However, they come with some DNS features

Why Route 53 ?

Route 53 can make use of:
a) Public domain name. E.g myapp.publicdomainname.com
b) Private domain names that can be resolved in your VPC(Virtual Private Cloud — another resource in AWS). E.g app.company.internal

It also has other advantages like:

  • Can perform load balancing
  • Availability Monitoring: Can perform health checks on your instances
  • Can route users to different services based on location
  • Has different routing policies like Simple, failover, latency, geolocation and weighted.
  • Domain Registration

Note: You pay $0.5 per month per hosted zone for AWS Route 53

Setting Up Route 53

First, you will need to register a domain either within Route53 or from a 3rd party registrar.

Register Your Domain

For this tutorial, we will be using 3rd party registrars. You can use either of the following domain registrars: GoDaddy, Namecheap, Bluehost, Google Domains, Domain.com or any other registrar of your choice. However, you may already have your domain registered, that’s fine also.

Create a hosted Zone on AWS Route 53

  • Login to your AWS, search for Route 53 and select it.
  • Choose Hosted Zones from the left menu or select Create Hosted Zone from the dashboard
  • Enter your domain name, enter a description (optional), then select Public under Type
  • Then click Create hosted zone
Creating a hosted zone in Route 53
Creating a hosted zone in AWS Route 53

Once this is created, you will be presented with up to 4 nameservers(NS) records. Go to your domain registrar dashboard and add these records to the NS records.

NS Records from Route 53 in AWS

Let us visit our domain registrar and add the records to the domain. I am using Namecheap but it is similar if you are using any other domain registrar. Login to your registrar, click the domain and click Manage.

Add the 4 nameservers like so:

Let’s Create our AWS EC2 Instance — Location of our resource/application

This tutorial assumes you are deploying your web applicaiton on an amazon EC2 instance. However, you could also deploy it somewhere else. The main point is having an IP address to locate that resource on which HTTP protocol is enabled.

Here are steps to quickly spin up an EC2 instance. onAWS:

  • Search for EC2 in the search box of your AWS console. Choose a region, if you haven’t done so already
  • Choose an AMI (Amazon Machine Image) — Select Amazon Linux 2 (with free tier)
  • Under type of machine, select t2-micro, this wont cost you money.
  • Click Review and Launch. However, you can choose Next and iterate over other configurations but note that some of these configurations may attract extra charge.
  • Create a new key pair and download it. Or use existing key pair.

Install Apache Web Server to Allow your EC2 Access on the Web Browser

  • Open your EC2. Locate and copy the Public IP of the EC2.
  • Open Terminal and type:
ssh -i xxxx.pem ec2-user@IP

Replace xxx.pem with the name and location of your download keypair. Also replace IP with the public IP address of your EC2

  • Run the following commands in your terminal, after SSHing into it
yum updateyum install -y httpd.x86_64       (Installs httpd)   systemctl start httpd.service     (Start httpd service)systemctl enable httpd.service    (Enabled across reboots)curl localhost:80

At this point, if you visit http://<IP_Address>, it will timeout unless you create security group and open HTTP port 80.

Create Inbound HTTP Security Group

  • Click on Security tab and click the Security group.
  • At the top right, drop down Actions and click Edit Inbound Rules
  • Click Add rule. Select HTTP under Type and type 0.0.0.0/0 under Source. You can also add description.
  • Click Save rule

Now visit http://<IP_Address> and you will have this page

At this point, you can spin up as many EC2 instances as you wish and deploy different applications to them. You can also have separate servers hosted in different places as long as you have their IP addresses.

Back to our Route 53 configuration

Let’s assume you have 3 instances/servers with IP addresses:
11.22.33.44
12.34.56.78
13.24.35.46

We will be creating 3 Route 53 A records that points to each of these IP addresses. We will also create Geolocation Routing Policy that routes users from a particular location to a different server.

Create A Records

  • Go to your Route 53 service, click on Hosted Zones
  • Select the domain name
  • Select Simple routing under Routing policy
  • Enter a value in TTL or leave as 300ms. TTL is explained below
  • Click Create record button
  • In the next screen, leave the record name blank. Slect A, in the record type and enter the IP address of your instance in the value field. This send the root domain name to the instance specified

Create other A Records

  • Click Create record button again
  • Enter the app name in the Record name field, select A record type and enter the first IP address of the instance
  • Under TTL (Time to Live), select or enter any value of your choice.

TTL (Time To Live) is in seconds and it is the number of seconds the record is cached on the browser. If the time has not elapsed and a new request is made, it takes from the browser cache. Otherwise, it goes to the DNS.

High TTL value means less traffic to the DNS. E.g 24hr

Low TTL Value means high traffic to the DNS. E.g 300ms

  • Select Simple routing under Routing policy
  • Click Save records

Now, when you visite either the domain name or appname.domainname.com, it routes the browser to the specific instance.

Repeat these steps in creating A records for other IP addresses.

Creating Geolocation Routing Policy on Route 53

This is routing based on location of the user. For example, traffic from UK or North America should go to a specific IP. In this policy, you should also create a “default” policy in case no location match was found.

Here are the steps to do that:

  • Click Create record.
  • Enter the app name (or leave blank for root domain record)
  • Select A record under record type
  • Enter the IP address in. thevalue box
  • Under Routing Policy, select Geolocation. More fields will appear.
  • Select “North America” or any location from where you would like to redirect users.
  • Type in an identifier in the Record ID so as to differentiate it from other records.
  • Click Create record

Voila! Aaaaaand, we are done

Conclusion

This article is not exhaustive of all what Route 53 can do but it has done justice to explaining ambigous terms in routing and DNS, explained how to spin up and host your application on an EC2 instance, how to setup Route 53 to manage your DNS and many more.

Should you have any clarifications, kindly DM me on Twitter or connect on LinkedIn.

Also, if this article has made any impact, kindly drop me a comment below.

--

--

Olutunmbi Banto
Webtips

Software Engineer — Building mobile and web applications with Node, React, Angular, PHP | Cloud| ALC Mentor and Facilitator at Andela | Tech Writer at @itnex_io