0
0
AWScloud~5 mins

Route 53 with ELB integration in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want your website to be reachable by a friendly name instead of an IP address, you use Route 53 to manage domain names. Integrating Route 53 with an Elastic Load Balancer (ELB) helps direct traffic to your application servers automatically and reliably.
When you want users to access your app using a domain name like example.com instead of an IP address.
When you have multiple servers behind a load balancer and want Route 53 to send traffic to the load balancer.
When you want automatic failover if one server goes down, using ELB's health checks.
When you want to manage DNS records easily in AWS for your web applications.
When you want to use AWS services to handle both domain names and traffic distribution.
Config File - elb-route53.json
elb-route53.json
{
  "Comment": "Create alias record for ELB in Route 53",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "AliasTarget": {
          "HostedZoneId": "Z35SXDOTRQ7X7K", 
          "DNSName": "my-load-balancer-1234567890.us-east-1.elb.amazonaws.com.",
          "EvaluateTargetHealth": false
        }
      }
    }
  ]
}

This JSON file is used with the AWS CLI to create an alias record in Route 53.

Name is your domain name.

Type A means it points to an IPv4 address or alias.

AliasTarget points to your ELB's DNS name and hosted zone ID.

EvaluateTargetHealth set to false means Route 53 won't check ELB health for routing.

Commands
This command creates an alias record in Route 53 pointing your domain to the ELB. It uses the JSON file to specify the record details.
Terminal
aws route53 change-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI --change-batch file://elb-route53.json
Expected OutputExpected
{ "ChangeInfo": { "Id": "/change/C2682N5HXP0BZ4", "Status": "PENDING", "SubmittedAt": "2024-06-01T12:00:00Z", "Comment": "Create alias record for ELB in Route 53" } }
--hosted-zone-id - Specifies the Route 53 hosted zone where the record will be created.
--change-batch - Points to the JSON file with the record change details.
This command checks that the alias record for example.com was created and points to the ELB.
Terminal
aws route53 list-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI --query "ResourceRecordSets[?Name == 'example.com.']"
Expected OutputExpected
[ { "Name": "example.com.", "Type": "A", "AliasTarget": { "HostedZoneId": "Z35SXDOTRQ7X7K", "DNSName": "my-load-balancer-1234567890.us-east-1.elb.amazonaws.com.", "EvaluateTargetHealth": false } } ]
--hosted-zone-id - Specifies the hosted zone to query.
--query - Filters output to show only the record for example.com.
Key Concept

If you remember nothing else from this pattern, remember: Route 53 alias records let you point your domain name directly to an ELB without needing an IP address.

Common Mistakes
Using the ELB DNS name without the trailing dot in the AliasTarget DNSName.
Without the trailing dot, Route 53 treats it as a relative name and the record creation fails.
Always include the trailing dot at the end of the ELB DNS name in the AliasTarget.
Using the wrong HostedZoneId for the ELB in the AliasTarget.
Each ELB has a specific hosted zone ID; using the wrong one causes Route 53 to reject the alias record.
Find the correct ELB hosted zone ID from AWS documentation or by describing the ELB and use it exactly.
Trying to create a CNAME record for the root domain (example.com) instead of an alias A record.
DNS standards do not allow CNAME records at the root domain, causing DNS resolution issues.
Use an alias A record in Route 53 for root domains pointing to ELB.
Summary
Create a JSON file defining an alias A record pointing your domain to the ELB DNS name with the correct hosted zone ID.
Use the AWS CLI command 'change-resource-record-sets' with the JSON file to create the record in Route 53.
Verify the record creation by listing resource record sets filtered by your domain name.