How To Set Amazon Route 53 To Manage Your Domain Using Three Methods To Do It
Introduction
Setting up Amazon Route 53 on AWS to manage your domain’s DNS records involves several steps. Route 53 is a scalable and highly available Domain Name System (DNS) web service.
The following lines give you a step-by-step guide to help you get started with Route 53 using the Console.
Pre-requisites
- Ensure you have an AWS account (Amazon Web Services).
- You also need a domain name, which you can get from various domain name providers, such as Bluehost and GoDaddy, to name a few.
- Last, you need a web server up and running, which you can access over the internet. See the screenshots below.
Method One: Doing It from the Console
Step One: Create a Hosted Zone
Sign in to the AWS Management Console.
Navigate to the Route 53 dashboard.
Click on Hosted zones in the navigation pane. Click on Create Hosted Zone. And, Enter the Domain Name you want to manage with Route 53.
Select the Type “ Public Hosted Zone “ for public DNS management.
Optionally, add tags to help organize your AWS resources.
Last, Click Create hosted zone.
I used t2s-academy.tech for this demo as my domain, which I purchased from Bluehost. I have been using Bluehost for quite some time for my other websites.
Step Two: Configure DNS Records
After creating your hosted zone, you’ll be directed to the management page for that zone.
There, you’ll see these two records. We will deal with them later.
Now, let’s create two additional records, as seen below. The first record will be as below.
Leave the Record name blank. For the Record type, choose A—Routes traffic to an IPv4 address and some AWS resources.
That’s what you need since you will use the Web Server’s IPv4 address as the Value.
Then, click Create records.
Create another record. This time, do the following:
- Record name: add www.
- For Record type, choose A — Routes traffic to an IPv4 address and some AWS resources.
- Select Alias. For Route traffic, select Alias to another record in this hosted zone.
- Then, select your domain (E.g., t2s-academy.tech).
- Click Create records.
When done right, you should see something like this showing the two newly added records:
What we’ve done above is first to point t2s-academy.tech to the instance’s IPv4 address.
Also, we created a record that will allow us to use www.t2s-academy.tech and still point to our Web Server (instance).
Step Three: Update Nameservers (if using Route 53 as your DNS service)
This step shows you how to update the nameservers to point to Route53 if the domain we’re using is registered with another registrar.
Since I got my domain, t2s-academy.tech, from Bluehost, I will need to ensure that it points out to AWS Route53 when someone uses it.
Two things you do: first, go back to your nameservers on Route53.
Next, update your domain’s nameservers on your registrar to match what you have on Route53.
In my case, and since I’m using Bluehost, the DNS dashboard may look different from yours if you’re using a different domain provider.
The propagation of DNS nameservers can take anywhere from a few minutes to up to 48 hours.
Additionally, Route53 includes features such as configuring Health Checks and setting up Routing Policies.
We will not do that, but I will discuss those two features in a future article.
If everything is done the way it should, you should use the Web Server’s IPv4 address and see this:
You can access your web server just by using t2s-academy.tech.
Lastly, if you use www.t2s-academy.tech you can still access your Instance.
You can even access your Web Server on the phone using either www.t2s-academy.tech or t2s-academy.tech.
Method Two: Using The AWS CLI
Create a Hosted Zone for your Domain t2s-academy.tech
aws route53 create-hosted-zone --name t2s-academy.tech --caller-reference $(date +%s)
This command will return a JSON response with details of the created hosted zone, including the Hosted Zone ID.
Add Record Sets to Your Hosted Zone
Create a JSON file record-set.json with the following content to add a record set for www.t2s-academy.tech :
{
"Comment": "Update record to reflect new IP address for example.com",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.t2s-academy.tech",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "34.228.38.235"
}
]
}
}
]
}
Replace YOUR_IP_ADDRESS with the IP address of your web server.
Apply the Record Set
Use the following command to apply the record set:
aws route53 change-resource-record-sets --hosted-zone-id Z00833142XH70HI6FI8Y9 --change-batch file://record-set.json
Verify the DNS Configuration
It may take some time for the DNS changes to propagate. You can verify the DNS records using a tool like dig or online DNS checkers. Run:
dig www.t2s-academy.tech
You can also validate everything using the instance’s IPv4 address, t2s-academy-tech, or www.t2s-academy-tech over the internet browser to access your Web Application just like we did earlier.
Using Cloud Formation To Do It
Create a CloudFormation Template
Create a CloudFormation template to set up a Route 53 hosted zone and optionally add DNS records.
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to create a Route 53 hosted zone for t2s-academy.tech
Resources:
MyHostedZone:
Type: 'AWS::Route53::HostedZone'
Properties:
Name: t2s-academy.tech
MyARecord:
Type: 'AWS::Route53::RecordSet'
Properties:
HostedZoneId: !Ref MyHostedZone
Name: t2s-academy.tech
Type: A
TTL: '60'
ResourceRecords:
- '192.0.2.44' # Replace with your IP address or use an appropriate AWS service
MyCNAMERecord:
Type: 'AWS::Route53::RecordSet'
Properties:
HostedZoneId: !Ref MyHostedZone
Name: www.t2s-academy.tech
Type: CNAME
TTL: '60'
ResourceRecords:
- 't2s-academy.tech' # Replace with the actual CNAME target
Deploy the CloudFormation Stack
Go to the AWS Management Console, navigate to the CloudFormation service, and create a new stack.
Choose Template: Upload the CloudFormation template you created.
Stack Name: Enter a name for the stack: e.g. Route53. Provide appropriate values for Parameters if you have any parameters defined in the template.
Review and Create: Review the configuration and create the stack.
Verify the Hosted Zone and DNS Records
The stack will take a little bit of time to complete. You check the status by clicking Events.
After the stack is created, go to the Route 53 service in the AWS Management Console and you should see your Hosted zone, t2s-academy.tech.
Click on the Hosted zone, t2s-academy.tech, to see all the records you’ve created through this project.
What you will need to do next is to replace the IPv4 address of your web server that you will add as Value/Route traffic to on the A Record name.
Then, you will be able to access your web application over the Internet.
Remember to clean up. To do so, check out the screenshot below:
In case your Hosted zone is not deleted, go back to the Route53 Dashboard. Then, delete the Hosted zone from there.
Method Three: Using Terraform To Do It
You will need to create this Directory structure as follows:
/terraform
├── main.tf
├── variables.tf
├── output.tf
├── terraform.tfvars
Create a variables.tf file
Add the following content to the variables.tf:
variable "aws_region" {
description = "The AWS region where to create our resources"
type = string
}
variable "domain_name" {
description = "The domain name you create the hosted zone for."
type = string
}
variable "A_record_ip" {
description = "The IP address for the A record."
type = string
}
variable "CNAME_record_target" {
description = "The CNAME record target."
type = string
}
Create a terraform.tfvars file and add the desired content
This file contains sensitive information that you would not want to expose to anyone.
Another approach is to use the following commands:
export TF_VAR_aws_access_key=<access_key_value>
export TF_VAR_aws_secret_key=<secret_key_value>
export TF_VAR_aws_region=<region>
export TF_VAR_username=<username_value>
export TF_VAR_password=<password_value>
For our project, we will use the terraform.tfvars and add this code:
aws_region = "us-east-1"
domain_name = "t2s-academy.tech"
A_record_ip = "192.0.2.44"
CNAME_record_target = "t2s-academy.tech"
Create an output.tf file
This file will display information about the resources you create.
output "zone_id" {
description = "The ID of the created Route 53 hosted zone."
value = aws_route53_zone.t2s_academy_tech.zone_id
}
output "name_servers" {
description = "The name servers of the created Route 53 hosted zone."
value = aws_route53_zone.t2s_academy_tech.name_servers
}
Create a main.tf file
On this file, you add code that references the variables you have on the variables.tf.
provider "aws" {
region = var.aws_region
}
resource "aws_route53_zone" "t2s_academy_tech" {
name = var.domain_name
}
resource "aws_route53_record" "A_record" {
zone_id = aws_route53_zone.t2s_academy_tech.zone_id
name = var.domain_name
type = "A"
ttl = "60"
records = [var.A_record_ip]
}
resource "aws_route53_record" "CNAME_record" {
zone_id = aws_route53_zone.t2s_academy_tech.zone_id
name = "www.${var.domain_name}"
type = "CNAME"
ttl = "60"
records = [var.CNAME_record_target]
}
After you have created the above Terraform files, main.tf, output.tf, variables.tf, and terraform.tfvars, go ahead and run first this command
terraform init
The terraform init command will initialize your repository.
terraform plan
The terraform plan command displays a preview of all the resources you want to create.
Next, terraform apply command will apply all the configurations and create the desired resources.
terraform apply
Ensure you type in yes at the Enter a value line.
This is how all looks when all the resources have been created.
Use terraform output to see the outputs (zone ID and name servers):
terraform output
Yes, you’ve done it using Terraform!
Now, you need to clean up. And, to do so, use this command:
terraform destroy
Always, make sure you verify that your infrastructure is destroyed.
Conclusion
As you’ve seen in this article, Amazon Route 53 is a scalable and reliable DNS web service that translates domain names into IP addresses. This is crucial for routing user requests to internet applications. It enhances performance and availability through domain registration, DNS health checks, and traffic flow management. Happy learning, and God bless you!