How do I configure geoproximity routing for traffic in Amazon Route 53 using the AWS Command Line Interface (AWS CLI)?

You can route traffic based on the physical distance between your users and your resources using geoproximity routing in Route 53. You can configure geoproximity routing using the AWS CLI by creating a traffic policy document and resource record sets in your hosted zone that use the traffic policy.

To create a geoproximity routing policy using the Amazon Route 53 console, see How do I configure geoproximity routing using the Route 53 console?

Create your traffic policy

Be sure that you install the latest version of the AWS CLI before proceeding.

1. Sign in to the AWS CLI.

2. Create a traffic policy document JSON file (for example, geoprox-rule.json) using the format for a geoproximity traffic policy. Be sure that you specify the necessary objects for geoproximity rules. For example:

{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"geoprox-rule",
  "Endpoints":{
    "aws-us-west-1-region":{
      "Type":"elastic-load-balancer",
      "Value":"elb-123456.us-west-1.elb.amazonaws.com"
    },
    "london-data-center":{
      "Type":"value",
      "Value":"192.0.2.1"
    }
  },
  "Rules":{
    "geoprox-rule":{
      "RuleType": "geoproximity",
      "GeoproximityLocations": [
        {
          "EndpointReference": "aws-us-west-1-region",
          "Region": "aws:route53:us-west-1",
          "Bias": "10",
          "HealthCheck": "11111111-1111-1111-1111-111111111111"
        },
        {
          "EndpointReference": "london-data-center",
          "Latitude": "51.50",
          "Longitude": "-0.16",
          "Bias": "0",
          "HealthCheck": "22222222-2222-2222-2222-222222222222"
        }
      ]
    }
  }
}

3. Use the command create-traffic-policy to create your traffic policy (for example, geoproximity-traffic-policy-cli) using the traffic policy document you just created.

$ aws route53 create-traffic-policy --name geoproximity-traffic-policy-cli --document file://geoprox-rule.json

4. Use the command create-traffic-policy-instance to create resource record sets in your hosted zone based on the settings in your traffic policy. Be sure that you specify the policy name (--name), traffic policy ID (--traffic-policy-id) and traffic policy version (--traffic-policy-version).

aws route53 create-traffic-policy-instance --hosted-zone-id <HostedZoneID> --name  <domain_or_sub-domain_name> --ttl 5

--traffic-policy-id <TrafficPolicyID> --traffic-policy-version <TrafficPolicyVersion>

5. Use dig to check that Route 53 correctly routes traffic based on geographic distance between the origination DNS client or resolver to the Region where the endpoints are located.

$ dig geoproximity-test-cli.shreekac.myinstance.com +short
 192.0.2.1

Traffic policy creation errors

An error occurred (TrafficPolicyInstanceAlreadyExists) when calling the CreateTrafficPolicyInstance operation: An instance with the same name and type already exists
You're trying to create a traffic policy, but a traffic policy record with that name already exists. Use a different policy name.

An error occurred (NoSuchTrafficPolicy) when calling the CreateTrafficPolicyInstance operation
The state machine for the operation hasn't synced yet. Retry your call after a while.

An error occurred (InvalidTrafficPolicyDocument) when calling the CreateTrafficPolicy operation: The document is not in valid JSON format at line 1, column 8
Prefix the value of --document with file:// in your create-traffic-policy command.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-08-24