How do I create Route 53 traffic policy records using the AWS CLI?

3 minute read

I want to create traffic policy records in Amazon Route 53 to route DNS traffic flow to multiple resources.

Short description

You can use the AWS Command Line Interface (AWS CLI) to create Route 53 traffic policy records. Before you begin, install and configure the AWS CLI.

If you want to use the Route 53 console to create a traffic policy, then see Creating a traffic policy.


Create a traffic policy with the AWS CLI

Create a JSON file that defines your traffic policy configuration. For basic syntax, endpoints, and rules, refer to Traffic policy document format.

To create your traffic policy in the AWS CLI, run the create-traffic-policy command with your own parameters:

$ aws route53 create-traffic-policy --name POLICY_NAME --document file://JSON_FILE

Note: Replace POLICY_NAME with your policy name. Replace JSON_FILE with the full path of your JSON file.

The following parameters are required:

  • --name
  • --document

The following parameters are optional:

  • --comment
  • --cli-input-json
  • --generate-cli-skeleton

In the output, note the traffic policy ID and version number:

  "TrafficPolicy": {
    "Document": JSON_DOCUMENT,
    "Version": VERSION_NUMBER,
    "Type": "POLICY_TYPE",
    "Name": "POLICY_NAME"

To create a traffic policy record, run the create-traffic-policy-instance API call.

$ aws route53 create-traffic-policy-instance --hosted-zone-id VALUE --name VALUE --ttl VALUE --traffic-policy-id VALUE --traffic-policy-version VALUE

Note: Replace each VALUE with your relevant value for that parameter.

Example traffic policy

The following example traffic policy creates a weighted record that points to two endpoints.

This policy specifies the following values:

  • The current policy format version (AWSPolicyFormatVersion)
  • The record type (RecordType)
    Note: Configure this value based on your endpoint type. In this example, the record type is A.
  • Two endpoints (EndPointReference) that point to IP addresses (Type)
  • Weighted rules (RuleType) and a different weight for each endpoint (Weight)
  • The traffic policy's starting point
    Note: In the following example, StartRule specifies the policy starts with a rule instead of an endpoint (StartEndpoint).
  • The health check setting (EvaluateTargetHealth)
    Note: You can configure this setting with HealthCheck. The following example does not perform a health check.
  "AWSPolicyFormatVersion": "2015-10-01",
  "RecordType": "A",
  "Endpoints": {
    "endpoint-1": {
      "Type": "value",
      "Value": ""
    "endpoint-2": {
      "Type": "value",
      "Value": ""
  "Rules": {
    "weighted-rule-name": {
      "RuleType": "weighted",
      "Items": [
        {"Weight": "30",
        "EvaluateTargetHealth": true,
        "EndpointReference": "endpoint-1"
        {"Weight": "20",
        "EvaluateTargetHealth": false,
        "EndpointReference": "endpoint-2"
  "StartRule": "weighted-rule-name"

Related Information

Supported DNS record types

AWS OFFICIALUpdated a year ago