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

Lesedauer: 2 Minute

I want to use AWS Command Line Interface (AWS CLI) to create traffic policy records in Amazon Route 53 to route DNS traffic flow to multiple resources.


Note: You can also create traffic policies through the Route 53 console.

Create a traffic policy with the AWS CLI

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

Use the command create-traffic-policy with your own parameters to create your traffic policy in the AWS CLI:

$ aws route53 create-traffic-policy --name <Value> --document file://<Full Path for 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.

Example output format:

  "TrafficPolicy": {
    "Document": <JSON_Document>,
    "Version": <Version_Number>,
    "Type": "<Policy_Type>",
    "Id": "<Traffic_Policy_ID>",
    "Name": "<Policy_Name>"

Create a traffic policy record using 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>

Example traffic policy

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

Note that the policy specifies:

  • The current policy format version (AWSPolicyFormatVersion)
  • The record type (RecordType). 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. In this example, StartRule specifies the policy starts with a rule instead of an endpoint (StartEndpoint).
  • The health check setting (EvaluateTargetHealth), which you can configure further with HealthCheck. In this example, no health check is performed.
  "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 OFFICIALAktualisiert vor 5 Jahren
Keine Kommentare