DEV Community

Cover image for Route53 With Application Loadbalancer
Clinton Ogechi
Clinton Ogechi

Posted on • Updated on

Route53 With Application Loadbalancer

Amazon Route 53 is a scalable and highly available Domain Name System (DNS) web service that allows you to manage and route traffic to your resources in a reliable and cost-effective way. Amazon Route 53, combined with the powerful Application Load Balancer (ALB), provides a robust solution to distribute traffic across EC2 instances in multiple availability zones.

Step 1: Set Up the Application Load Balancer (ALB)

1. Launch Two EC2 Instances

  • Open the AWS Management Console and navigate to the EC2 dashboard.
  • Launch two EC2 instances in different availability zones (e.g., us-east-1a and us-east-1b) with the same AMI and security group.
  • Ensure that both instances have HTTP and SSH ports enabled in their security group.
  • Add this bash script file for server 1.
#!/bin/bash
yum update -y
yum upgrade -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<h1>My Webserver 1</h1>" > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
  • Add this bash script file for server 2.
#!/bin/bash
yum update -y
yum upgrade -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<h1>My Webserver 2</h1>" > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

2. Create a Target Group

  • Navigate to Target Groups in the EC2 dashboard.
  • Click Create target group and select the Instances type.
  • Select your VPC and include both EC2 instances in the target group.
  • Ensure health checks are enabled for your instances.

Image description

Image description

Image description

Image description

Image description

Image description

3. Create the Application Load Balancer

  • Navigate to Load Balancers in the EC2 dashboard.
  • Click Create Load Balancer and select Application Load Balancer.
  • In the Network mapping section, select your VPC and choose the availability zones where your EC2 instances are running.
  • Assign the same security group that allows HTTP traffic.
  • Under Listeners and Routing, select the target group you created earlier.
  • Click Create Load Balancer.

Image description

Image description

Image description

Image description

4. Check the Status of the Load Balancer

  • Wait until the status of your Load Balancer changes from "Provisioning" to "Active."
  • Check the target group to ensure both EC2 instances are showing as healthy.

Image description

Step 2: Use AWS Provided DNS Name

1. Get the DNS Name of the Application Load Balancer

  • After the Load Balancer is created, go to the Load Balancers section in the EC2 dashboard.
  • Select your ALB, and you’ll see the DNS name of the Load Balancer.

2. Test the Load Balancer

  • Open a web browser and paste the ALB DNS name in the address bar.
  • You should be able to see the webpage served by one of your EC2 instances.
  • Refresh the browser a few times, and the request should switch between both EC2 instances.

Image description

Image description

Step 3: Route 53 Custom Domain Integration

1. Create a Hosted Zone in Route 53

  • In the AWS Management Console, navigate to Route 53.
  • Click on Hosted Zones and create a new hosted zone.

Image description

Image description

Image description

2. Create a CNAME Record

  • Go to the hosted zone you created.
  • Click Create Record and choose CNAME as the record type.
  • In Record name - www
  • Record type - CNAME
  • Value - DNS of our application load balancer we created in above steps.
  • Click on Create records.

Image description

  • Now we need to copy the NS record type → all 4 Value/Route traffic and paste it in the name servers of our purchased domain.

Image description

  • In web browser search your domain name and the request will be served from both the instances. You can test this setup using the DNS name provided by the ALB, as you won't be able to route traffic using the placeholder domain without proper registration.

Conclusion

By successfully integrating Amazon Route 53 with an Application Load Balancer, you've implemented a highly available and fault-tolerant architecture that optimizes traffic distribution across multiple EC2 instances. This setup not only enhances application performance but also ensures that requests are dynamically routed to healthy instances in multiple availability zones.

Top comments (0)