Skip to content

Amazon Route 53

Wonkeun No edited this page Jan 16, 2023 · 8 revisions

Table of Contents

What is DNS?

Introduction to Domain Name System by Amazon Web Service

Route 53 Overview

Route53 is a DNS service provided by Amazon. It is a very powerful tool that can be used to create a highly available and scalable infrastructure. It is also a very complex tool that can be used to create a very complex infrastructure. This document will cover the basics of Route53 and how to use it to create a simple infrastructure.

Below diagram simplifies what Amazon Route 53 does as DNS service. One of the benefits using Route 53 is to monitor AWS instances and send the traffic to an appropriate instance. If Seneca ITS needs global service, it can be very useful. At least, Route 53 can monitor the instance's health and send the traffic to other instances when needed.

image

Route 53 can be configured easily with AWS services, but also with other non AWS resources.

Route 53 Explained and Tutorial by Simplilearn

Route 53 Features

  • Route 53 Resolver: Conditional forwarding rules and DNS endpoints can be created in Route 53 private hosted zones or in on-premises DNS servers. Also outbound DNS traffic can be filtered by firewall.
  • Route 53 Application Recovery Controller: Check that resources are available. Re-routing traffic when failover occurs. Set up safety rules.
  • Global traffic control
  • Latency based & IP based routing
  • Geo DNS
  • Private DNS for Amazon VPC (Amazon internal resources)
  • Domain registration
  • CloudFront & S3 Zone Apex support: website can be accessed at root domain (i.e. access to example.com instead of www.example.com)
  • Integration with Elastic Load Balancing
  • Management Console support
  • Weighted Round Robin: Specify the frequency with which different DNS responses are returned to end users.

Infrastructure

​ Before we can configure Route53, we need to know the infrastructure we would like to setup. In Starchart's case that is a simple URL with some components, like web322.alex.starchart.com which can point to any external server (A record) or redirect to another URL (CNAME record).

URL Components

​ All the domains provided through Starchart will have a similar pattern to them. The pattern includes the following components: ​

  • Top-Level Domain (starchart.com): The TLD that will be a part of every domain provided by Starchart. This is the domain that will have a hosting zone configured on Route53.
  • Student Name (alex.): A sub-domain that will be unique to each student and will be used to identify the student's infrastructure. The user can configure DNS records for this sub-domain.
  • Project Name (web322.): This is the name of the project that the student is working on, and can be configured only by that student. The user can configure DNS records for this sub-domain.

DNS Record Configuration

​ The user can set DNS records for the following:

  • User-level root domain: Just alex.starchart.com, common use case could be to redirect to a personal website.
  • Project-level root domain: Just web322.alex.starchart.com, common use case could be to redirect to a course project website. ​ And finally, depending on the project specification, a wildcard project-level (*.alex.starchart.com) domain could be used in different ways:
  • Let the user configure DNS records for the wildcard domain, so if someone visits a non-existent domain such as 404.alex.starchart.com it will follow the user-configured DNS records.
  • Redirect the wildcard domain to the user-level root domain, so if someone visits a non-existent domain such as 404.alex.starchart.com it will *automatically redirect to alex.starchart.com.
  • Show a 404 page, so if someone visits a non-existent domain such as 404.alex.starchart.com it will show a static 404 page.

Ways of Accessing Route 53

  • AWS SDK
  • Route 53 API
  • AWS CLI or AWS Tools for PowerShell
  • AWS Management Console

Setup Using Management Console

In this setup I will use the TLD bytechlabs.com (this will be starchart.com in our case) registered via Namecheap (a domain registrar). ​

1. Create a Hosting Zone (via Route53)

Visit the Route53 dashboard, and click on the "Create hosted zone" button. Route53 dashboard

This will take you to the "Create hosted zone" page, where you will need to enter the domain name you want to create a hosting zone for. In our case, we will use bytechlabs.com.

Create hosted zone

After clicking on the "Create hosted zone" button, you will be taken to a similar page as below, and will be given a list of 4 nameservers.

Create hosted zone

POST /2013-04-01/hostedzone HTTP/1.1
<?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
    <CallerReference>string</CallerReference>
    <DelegationSetId>string</DelegationSetId>
    <HostedZoneConfig>
        <Comment>string</Comment>
        <PrivateZone>boolean</PrivateZone>
    </HostedZoneConfig>
    <Name>stirng</Name>
    <VPC>
        <VPCId>string</VPCId>
        <VPCRegion>string</VPCRegion>
    </VPC>
</CreateHostedZoneRequest>
var params = {
  CallerReference: 'STRING_VALUE', /* required */
  Name: 'STRING_VALUE', /* required */
  DelegationSetId: 'STRING_VALUE',
  HostedZoneConfig: {
    Comment: 'STRING_VALUE',
    PrivateZone: true || false
  },
  VPC: {
    VPCId: 'STRING_VALUE',
    VPCRegion: us-east-1 | us-east-2 | us-west-1 | us-west-2 | eu-west-1 | eu-west-2 | eu-west-3 | eu-central-1 | eu-central-2 | ap-east-1 | me-south-1 | us-gov-west-1 | us-gov-east-1 | us-iso-east-1 | us-iso-west-1 | us-isob-east-1 | me-central-1 | ap-southeast-1 | ap-southeast-2 | ap-southeast-3 | ap-south-1 | ap-south-2 | ap-northeast-1 | ap-northeast-2 | ap-northeast-3 | eu-north-1 | sa-east-1 | ca-central-1 | cn-north-1 | af-south-1 | eu-south-1 | eu-south-2
  }
};
route53.createHostedZone(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

2. Update the Nameservers (via your domain registrar)

Now that we have the nameservers, we need to update the nameservers for our domain bytechlabs.com to the ones provided by Route53. The process of updating the nameservers will vary depending on the domain registrar you are using. In my case, I am using Namecheap, so I will show you how to update the nameservers for Namecheap. ​ Open the Namecheap dashboard, and open your domain's settings page. You will see a Nameservers section, where you can update the nameservers. Make sure to switch the DNS from Namecheap DNS to Custom DNS. This will allow you to enter your own nameservers. Create the 4 nameservers provided by Route53, and click on the "Save" button. Namecheap dashboard

Operating Route 53 (Creating DNS Records)

Now that we have our hosted zone created, and our nameservers updated, we can start creating DNS records. DNS records are how you define what happens when a certain domain is visited, for example, what happens if we visit alex.starchart.com, or web322.alex.starchart.com, this will be the main workflow of Starchart.

1. Create a Record (via Route53)

Now that we have updated the nameservers, we can create a record for our domain. We will create a record to redirect from seneca.bytechlabs.com to myseneca.ca. Open the Route53 dashboard, click on the "Hosted zones" button on the left sidebar, and open the Hosted Zone for bytechlabs.com.

Route53 dashboard ​ Click on the "Create record" button, and enter the following details:

  • Name: seneca
  • Type: CNAME
  • Value: myseneca.ca
  • TTL: 300Create record ​ Fill in the details, and click on the "Create Record" button. This will create a record that will redirect seneca.bytechlabs.com to myseneca.ca. Create record

Note: All domain names and values in Route53 are stored as lowercase characters (So if you want to redirect to https://www.youtube.com/watch?v=dQw4w9WgXcQ, you will have to specify the uppercase characters using their 3-digit octal code available here, more info here.) ​

POST /2013-04-01/hostedzone/Id/rrset/ HTTP/1.1
<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
    <ChangeBatch>
        <Changes>
            <Change>
                <Action>string</Action>
                <ResourceRecordSet>
                    <AliasTaget>
                        <DNSName>string</DNSName>
                        <EvaluateTargetHealth>boolean</EvaluateTargetHealth>
                        <HostedZoneId>string</HostedZoneId>
                    </AliasTaget>
                    <CidrRoutingconfig>
                        <CollectionId>string</CollectionId>
                        <LocationName>string</LocationName>
                    </CidrRoutingconfig>
                    <Failover>string</Failover>
                    <GeoLocation>
                        <ContinentCode>string</ContinentCode>
                        <CountryCode>string</CountryCode>
                        <SubdivisionCode>string</SubdivisionCode>
                    </GeoLocation>
                    <HealthCheckId>string</HealthCheckId>
                    <MultiValueAnswer>boolean</MultiValueAnswer>
                    <Name>string</Name>
                    <Region>string</Region>
                    <ResourceRecords>
                        <ResourceRecord>
                            <Value>string</Value>
                        </ResourceRecord>
                    </ResourceRecords>
                    <SetIdentifier>string</SetIdentifier>
                    <TrafficPolicyInstanceId>string</TrafficPolicyInstanceId>
                    <TTL>long</TTL>       
                    <Type>string</Type>       
                    <Weight>long</Weight>       
                </ResourceRecordSet>
            </Change>
        </Changes>
        <Comment>string</Comment>
    </ChangeBatch>
</ChangeResourceRecordSetsRequest>
 var params = {
  ChangeBatch: {
   Changes: [
      {
     Action: "CREATE", 
     ResourceRecordSet: {
      Name: "example.com", 
      ResourceRecords: [
         {
        Value: "192.0.2.44"
       }
      ], 
      TTL: 60, 
      Type: "A"
     }
    }
   ], 
   Comment: "Web server for example.com"
  }, 
  HostedZoneId: "Z3M3LMPEXAMPLE"
 };
 route53.changeResourceRecordSets(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
   /*
   data = {
    ChangeInfo: {
     Comment: "Web server for example.com", 
     Id: "/change/C2682N5HXP0BZ4", 
     Status: "PENDING", 
     SubmittedAt: <Date Representation>
    }
   }
   */
 });

2. Confirm the Record

Now, if you visit seneca.bytechlabs.com, you will be redirected to myseneca.ca. To confirm the DNS record is working, you can use the dig command or use a website like MXToolbox. MXToolBox

Route 53 Management Console

Conclusion

The same workflow described above can be achieved using Route53's API, which can be used to automate the process of creating a hosting zone and creating records. ​ A possible infrastructure could look like this: User -> [ Starchart Frontent -> Starchart Backend ] -> Route53, where all the user data is processed in the Starchart abstraction layer and also provides authentication, authorization, and validation.