I Tried Out Affinity Routing in Amazon Route 53

I Tried Out Affinity Routing in Amazon Route 53

I tested Amazon Route 53 affinity routing. It returns the record in the client's AZ, falls back to Zone Group, Region, then Global, and returns Global for queries from outside the VPC in public hosted zones.
2026.11.28

This page has been translated by machine translation. View original

Introduction

On November 20, 2026, affinity routing for Amazon Route 53 was announced.

https://aws.amazon.com/about-aws/whats-new/2026/11/route-53-affinity-routing/

Affinity routing is a routing policy that responds to DNS queries from clients in a VPC with the record in the same AZ as the client. In this article, I verify the per-AZ responses and fallback in a private hosted zone, and the responses in a public hosted zone.

Test Environment

  • Region: Tokyo (ap-northeast-1)
  • aws-cli: 2.42.1
  • EC2: one t4g.nano running Amazon Linux 2023 (arm64) in each AZ
  • dig: installed at EC2 launch with dnf install -y bind-utils
  • Private hosted zone: az-affinity.test (associated with the default VPC)
  • Public hosted zone: an existing one (written as example.com)
  • Query target: VPC Resolver (172.31.0.2)

Configuration

AZ ID and Zone Group

For the LocationId of an AZ record, specify the AZ ID (such as apne1-az4) rather than the AZ name (such as ap-northeast-1a). This is because the AZ that an AZ name refers to may differ from account to account. You can get the AZ ID and Zone Group values with the following command.

aws ec2 describe-availability-zones \
  --region ap-northeast-1 \
  --filters Name=zone-type,Values=availability-zone \
  --query "AvailabilityZones[].[ZoneName,ZoneId,GroupName]" \
  --output text

The output shows, from left to right, the AZ name, AZ ID, and Zone Group. The three AZs in the Tokyo region were displayed.

ap-northeast-1a	apne1-az4	ap-northeast-1-zg-1
ap-northeast-1c	apne1-az1	ap-northeast-1-zg-1
ap-northeast-1d	apne1-az2	ap-northeast-1-zg-1

Records

I registered six A records with the same name, app.az-affinity.test, in the private hosted zone.

Value LocationType LocationId SetIdentifier
192.0.2.1 AvailabilityZone apne1-az1 az1
192.0.2.2 AvailabilityZone apne1-az2 az2
192.0.2.4 AvailabilityZone apne1-az4 az4
192.0.2.10 AvailabilityZoneGroup ap-northeast-1-zg-1 zone-group
192.0.2.20 Region ap-northeast-1 region
192.0.2.99 Global global global

For registration, I used a JSON file for change-resource-record-sets.

aws route53 change-resource-record-sets \
  --hosted-zone-id Z0123456789EXAMPLE \
  --change-batch file://phz-records-create.json
phz-records-create.json
{
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "az1",
        "AZAffinity": {
          "LocationType": "AvailabilityZone",
          "LocationId": "apne1-az1"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.1"
          }
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "az2",
        "AZAffinity": {
          "LocationType": "AvailabilityZone",
          "LocationId": "apne1-az2"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.2"
          }
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "az4",
        "AZAffinity": {
          "LocationType": "AvailabilityZone",
          "LocationId": "apne1-az4"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.4"
          }
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "zone-group",
        "AZAffinity": {
          "LocationType": "AvailabilityZoneGroup",
          "LocationId": "ap-northeast-1-zg-1"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.10"
          }
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "region",
        "AZAffinity": {
          "LocationType": "Region",
          "LocationId": "ap-northeast-1"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.20"
          }
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "app.az-affinity.test",
        "Type": "A",
        "SetIdentifier": "global",
        "AZAffinity": {
          "LocationType": "Global",
          "LocationId": "global"
        },
        "TTL": 5,
        "ResourceRecords": [
          {
            "Value": "192.0.2.99"
          }
        ]
      }
    }
  ]
}

Verification Method

After the update via change-resource-record-sets completed and the TTL (5 seconds) had passed, on each of the EC2 instances in the three AZs, I obtained the AZ ID from the instance metadata and queried the VPC Resolver with dig.

TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
echo "az-id=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone-id)"
dig app.az-affinity.test A +noall +answer +stats

Results

Private Hosted Zone

All three instances returned the value of the record corresponding to their own AZ.

EC2 AZ ID Response
apne1-az1 192.0.2.1
apne1-az2 192.0.2.2
apne1-az4 192.0.2.4

Fallback

I deleted the az4, Zone Group, and Region records one at a time in this order, and ran dig on all three instances each time.

The results on the apne1-az4 EC2 instance changed as follows.

  • After deleting the az4 record: 192.0.2.10 (the Zone Group record)
  • After also deleting the Zone Group record: 192.0.2.20 (the Region record)
  • After also deleting the Region record: 192.0.2.99 (the Global record)

The apne1-az1 and apne1-az2 EC2 instances still had their own AZ records, so they remained at 192.0.2.1 and 192.0.2.2 without change.

Public Hosted Zone

In the existing public hosted zone, I registered four A records for azaff.example.com: az1 (203.0.113.1), az2 (203.0.113.2), az4 (203.0.113.4), and Global (203.0.113.99).

Query source Response
EC2 in apne1-az1 203.0.113.1
EC2 in apne1-az2 203.0.113.2
EC2 in apne1-az4 203.0.113.4
Local PC outside the VPC (via stub resolver) 203.0.113.99
Local PC outside the VPC (directly specifying the hosted zone's name server) 203.0.113.99

Even with the public hosted zone, the record in the same AZ was returned to EC2 instances in the VPC. For queries from outside the VPC, the Global record was returned.

Summary

I tried affinity routing for Amazon Route 53 and confirmed that, in both private and public hosted zones, EC2 instances in the VPC receive the record in the same AZ.

If you want to reduce the latency and cost caused by cross-AZ communication within a VPC, give the newly supported affinity routing a try.

References

https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-azaffinity.html

Share this article

AWSのお困り事はクラスメソッドへ