DNS and AWS Route53 explained

I post content on backend concepts along with mini projects and implementations for the same.
Basic flow for DNS resolution
When you type a domain name like marketplace.easy-games.xyz in your browser this is what happens -
The browser and OS check their local DNS cache to see if the DNS record is present.
If not found, a query is sent to a recursive DNS resolver. This can be a public DNS resolver or your ISP’s resolver. For eg.- Some public DNS resolvers include 8.8.8.8(google DNS resolver), 1.1.1.1 (cloudflare resolver) etc . The DNS resolver’s job is to get the DNS record for the domain you just entered.
The DNS resolver checks its cache. If the record is not present in the cache it makes a query to a root name server to ask for the top level domain servers of .xyz. Root name servers hold NS records of the top level domain name servers of .com, .in, .net etc.
The resolver then makes a query to the one of the TLD name servers of .xyz to get records of name servers of easy-games.xyz. It returns the records of the authoritative name servers of easy-games.xyz.
The resolver then makes a query to one of the authoritative name servers of easy-games.xyz. There it finds the DNS record for marketplace.easy-games.xyz.
Depending on the record the resolver returns the value which is also cached on the resolver. Cache duration depends on the TTL of the record.
A domain name can point to an IP address, a domain or multiple IPs/domains.
AWS Route53
What Route53 is
Route53 is a domain registrar and an authoritative name server service. Domain registrar meaning you can register a domain on route53 for an yearly fee. This gives you ownership of the domain as long as you keep paying the yearly fee. Authoritative name servers are responsible for storing DNS records and are the final step of the DNS resolution process. You can make use of route53 name servers for the DNS records you purchase.
When you register a domain you can create any subdomain under it, for eg.- marketplace.easy-games.xyz or web.easy-games.xyz is available to you if you buy the easy-games.xyz domain.
After purchasing a domain you can create DNS records for that domain and its subdomains. To do this on AWS you first need to create a hosted zone in route53.
Hosted zone
A hosted zone is a container that holds information about how you want to route traffic for a domain. It holds DNS records for the domain plus its sub domains. A hosted zone has the same name as the corresponding domain (easy-games.xyz in our case).
You can create a public or a private hosted zone. We’ll be creating a public hosted zone for our case since we want our domain to be accessible from the internet. A private hosted zone can be created if all your traffic would be from inside your VPC.

After the hosted zone is created you would see that route53 has assigned 4 name servers for the domain. These name servers have access to the data of this hosted zone and would use that to resolve DNS queries.

Creating a DNS record
We’ll create a type A record with routing policy as simple for marketplace.easy-games.xyz. A type A record maps a domain to an IPv4 address or an AWS resource (if you enable the Alias option in the record). I have entered the value as a public IPv4 address.

You can use other routing policies as well. Some of these are -
Weighted - With the weighted policy, you create multiple records for the same domain with a weight that determines the percentage of requests resolving to that record. This is useful if you wish to test a new version of your application with a fraction of total users on production.
Failover - Here you can add primary and secondary records, if health checks to the primary record fail DNS will resolve to the secondary record. Health checks can be set up in route53.
Geolocation - Create multiple records with a specified location for each record. This is useful if you want users from a region to be redirected to servers in that region only.
Now the record marketplace.easy-games.xyz is created. But it won’t resolve to anything yet since we have not purchased and linked the domain to our hosted zone yet.
PS C:\Users\user> nslookup marketplace.easy-games.xyz
Server: UnKnown
Registering a domain on GoDaddy
You can register a domain on route53 too which is easier if you plan on using route53 for your DNS records. I am going to be registering one on godaddy and replacing the name servers there with route53 name servers.

After purchasing the domain you’ll see the option to change name servers.

Change the domain’s NS records from default to the ones assigned to our hosted zone.

I have added AWS name servers to the domain, these name servers have access to my hosted zone records and the domain marketplace.easy-games.xyz will now resolve successfully since I had already created a record for the same.
PS C:\Users\user> nslookup marketplace.easy-games.xyz
Server: UnKnown
Address: fe80::1
Non-authoritative answer:
Name: marketplace.easy-games.xyz
Address: 3.7.254.146
Thank you for reading !!



