AWS Route 53 DNS - Weighted Routing

- aws networking dns

This post is part of my note taking while studying for the AWS Certified Advanced Networking - Specialty certification.

Weighted routing policy has Route 53 DNS answer based on weight. You assign each record set (could be multiple values) a weight and Route 53 returns that a percentage of the time. What percentage of the time?

Weighted Policy equation

Sum of active weights refers to the sum of all record set weights that are active. Records with an associated health check that is failing will not be included. Anything with a weight of 0 will not be returned unless all records are set with a weight of 0. Then, all records will be returned the same amount of the time.

Let’s look at an example.

Below, the last record, will be returned 50% of the time (14/(1+1+1+1+1+1++7+14) or 1428). The second to last, 113.12.140.217, will be returned 25% of the time.

Weighted Policy Table 1

If that record’s health check fails, what will happen? It will no longer be returned. The second to last record, 113.12.140.217, will be returned now 50% of the time (7/(1+1+1+1+1+1+1+7) or 714).

Weighted Policy Table 2

Created a weighted resource record using the AWS CLI

You need to create a JSON file describing the record you wish to create.

weighted1.json

{
  "Comment": "Create first weighted record",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "cloudyweighted.cloudynetworks.net",
        "Type": "A",
        "SetIdentifier": "hostA",
        "Weight": 1,
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "127.0.0.1"
          },
        ],
      }
    },
  ]
}

weighted2.json

{
  "Comment": "Create first weighted record",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "cloudyweighted.cloudynetworks.net",
        "Type": "A",
        "SetIdentifier": "hostA",
        "Weight": 1,
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "127.0.0.2"
          },
        ],
      }
    },
  ]
}

You would then add the records to Route53.

$ aws route53 change-resource-record-sets --hosted-zone-id Z1R8UBAEXAMPLE --change-batch file://weighted1.json
$ aws route53 change-resource-record-sets --hosted-zone-id Z1R8UBAEXAMPLE --change-batch file://weighted2.json