0
0
AWScloud~5 mins

Routing policies (simple, weighted, latency) in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Routing policies in AWS help decide how internet traffic is directed to your resources. They solve the problem of managing traffic flow to different servers or regions based on simple rules, traffic weights, or connection speed.
When you want all users to go to a single server or resource without any special rules.
When you want to split traffic between two servers, for example, sending 70% to one and 30% to another.
When you want users to connect to the server that responds fastest to reduce delays.
When you are testing a new server and want to send only a small portion of traffic to it.
When you have servers in different regions and want users to connect to the closest one.
Config File - route53-records.json
route53-records.json
{
  "Comment": "Create Route53 records with different routing policies",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "192.0.2.1"}
        ],
        "SetIdentifier": "simple-record"
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "192.0.2.2"}
        ],
        "SetIdentifier": "weighted-record-1",
        "Weight": 70
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "192.0.2.3"}
        ],
        "SetIdentifier": "weighted-record-2",
        "Weight": 30
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "192.0.2.4"}
        ],
        "SetIdentifier": "latency-record-us-east-1",
        "Region": "us-east-1"
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "192.0.2.5"}
        ],
        "SetIdentifier": "latency-record-us-west-2",
        "Region": "us-west-2"
      }
    }
  ]
}

This JSON file defines multiple DNS records for the domain example.com using AWS Route53 routing policies.

  • Simple routing: Sends all traffic to 192.0.2.1.
  • Weighted routing: Splits traffic between 192.0.2.2 (70%) and 192.0.2.3 (30%).
  • Latency routing: Sends users to the server with the lowest latency based on their region, either 192.0.2.4 (us-east-1) or 192.0.2.5 (us-west-2).

Each record has a SetIdentifier to distinguish it and TTL to control caching time.

Commands
This command applies the DNS record changes defined in the JSON file to the hosted zone with ID Z3P5QSUBK4POTI. It creates the simple, weighted, and latency routing records.
Terminal
aws route53 change-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI --change-batch file://route53-records.json
Expected OutputExpected
{ "ChangeInfo": { "Id": "/change/C2682N5HXP0BZ4", "Status": "PENDING", "SubmittedAt": "2024-06-01T12:00:00Z", "Comment": "Create Route53 records with different routing policies" } }
--hosted-zone-id - Specifies the Route53 hosted zone where records will be changed
--change-batch - Points to the JSON file with the record changes
This command lists all DNS records in the hosted zone to verify that the new routing policies were created successfully.
Terminal
aws route53 list-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI
Expected OutputExpected
{ "ResourceRecordSets": [ { "Name": "example.com.", "Type": "A", "TTL": 60, "SetIdentifier": "simple-record", "ResourceRecords": [{"Value": "192.0.2.1"}] }, { "Name": "example.com.", "Type": "A", "TTL": 60, "SetIdentifier": "weighted-record-1", "Weight": 70, "ResourceRecords": [{"Value": "192.0.2.2"}] }, { "Name": "example.com.", "Type": "A", "TTL": 60, "SetIdentifier": "weighted-record-2", "Weight": 30, "ResourceRecords": [{"Value": "192.0.2.3"}] }, { "Name": "example.com.", "Type": "A", "TTL": 60, "SetIdentifier": "latency-record-us-east-1", "Region": "us-east-1", "ResourceRecords": [{"Value": "192.0.2.4"}] }, { "Name": "example.com.", "Type": "A", "TTL": 60, "SetIdentifier": "latency-record-us-west-2", "Region": "us-west-2", "ResourceRecords": [{"Value": "192.0.2.5"}] } ] }
--hosted-zone-id - Specifies the hosted zone to list records from
Key Concept

If you remember nothing else from this pattern, remember: routing policies control how DNS directs users to your servers based on simple rules, traffic weights, or connection speed.

Common Mistakes
Not setting unique SetIdentifier values for each record.
AWS Route53 requires unique identifiers to distinguish records with the same name and type but different routing policies.
Always provide a unique SetIdentifier for each routing policy record.
Using the same Weight value for weighted routing records.
Weights determine traffic split; identical weights cause equal traffic distribution, which may not be intended.
Assign different Weight values to control traffic percentages properly.
Omitting the Region field in latency routing records.
Latency routing depends on the Region to route users to the closest server; missing this causes routing failure.
Specify the Region for each latency routing record.
Summary
Create DNS records with different routing policies using a JSON change batch file.
Apply the changes to your Route53 hosted zone with the AWS CLI.
Verify the records were created correctly by listing them in the hosted zone.