

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 交通政策文件格式
<a name="api-policies-traffic-policy-document-format"></a>

当您使用 Amazon Route 53 API、其中一个软件开发 AWS 工具包、或以编程方式创建流量策略时 AWS Tools for Windows PowerShell，您可以在 JSON 格式的`Document`元素中指定流量策略的定义。 AWS CLI

有关流量策略的更多信息，请参阅 *Amazon Route 53 开发者指南中的使用流量路由* [DNS](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/traffic-flow.html) 流量。

**Topics**
+ [基本语法](#traffic-policy-document-format-basic)
+ [端点定义的语法](#traffic-policy-document-format-endpoints)
+ [规则定义的语法](#traffic-policy-document-format-rules)
+ [示例](#traffic-policy-document-format-examples)

## 基本语法
<a name="traffic-policy-document-format-basic"></a>

以下是流量策略文档的基本语法：

```
 1. {
 2.    "AWSPolicyFormatVersion": "2015-10-01 | 2023-05-09",
 3.    "RecordType": "{{DNS type for all resource record sets created by this traffic policy}}",
 4.    "StartEndpoint | StartRule": "{{ID that you assign to an endpoint or rule}}",
 5.    "Endpoints": {
 6.       "{{Endpoint ID that you assign}}": {
 7.          {{Endpoint definition}}
 8.       },
 9.       ...
10.    },
11.    "Rules": {
12.       "{{Rule ID that you assign}}": {
13.          {{Rule definition}}
14.       },
15.       ...
16.    }
17. }
```

流量策略文档的基本语法包含以下对象：

**AWSPolicyFormatVersion**  
流量策略格式的版本，支持 L AWS ocal Zones 的最新版本；`2023-05-09`。  
还支持以前的版本;`2015-10-01`.

**RecordType**  
Amazon Route 53 将根据此流量策略创建的所有资源记录集的 DNS 类型。如果要将流量路由到以下 AWS 资源，请选择适用的值：  
+ **CloudFront 分发** — 选择 **A: IPv4 格式的 IP 地址**或 **AAAA: IPv6 格式的 IP 地址**。
+ **ELB 应用程序负载均衡器** - 选择 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **ELB 经典负载均衡器** - 选择 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **ELB 网络负载均衡器** - 选择 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **Elastic Beanst** alk 环境 **— 选择 A：IPv4 格式的 IP 地址或 AAAA：****IPv6 格式**的 IP 地址。
+ **配置为网站终端节点的 Amazon S3 存储桶**：选择 **A: IP address in IPv4 format（A：IPv4 格式的 IP 地址）**。
如果要将流量路由到其他资源，请为该资源选择适用的类型。例如，如果要将流量路由到邮件服务器，请指定`MX`。有关 Route 53 支持的 DNS 类型列表，请参阅 *Amazon Route 53 开发者指南*中的[支持的 DNS 资源记录类型](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/ResourceRecordTypes.html)。

**StartEndpoint \| StartRule**  
无论您希望流量策略的起点是端点还是规则，以及您在流量策略文档其他地方为端点或规则分配的 ID。

**端点**  
您要在此流量策略中使用的终端节点的定义。有关更多信息，请参阅 [端点定义的语法](#traffic-policy-document-format-endpoints)。

**Rules**  
您要在此流量策略中使用的规则的定义。有关更多信息，请参阅 [规则定义的语法](#traffic-policy-document-format-rules)。

## 端点定义的语法
<a name="traffic-policy-document-format-endpoints"></a>

以下是您在流量策略文档中指定的端点定义的语法：

```
1. {
2.    "Type": value | cloudfront | application-load-balancer | elastic-load-balancer | network-load-balancer | elastic-beanstalk | s3-website,
3.    "Region": "AWS region that you created your Amazon S3 bucket in"
4.    "Value": "value applicable to the type of endpoint"
5. }
```

端点定义的语法包含以下对象：

**Type**  
指定适用的值：    
**值**  
要将流量路由到以下列表以外的资源，请指定`value``Type`。  
**cloudfront**  
要将流量路由到分 CloudFront 配，请指定`cloudfront``Type`。  
**应用程序负载均衡器**  
要将流量路由到 Application Load Balancer，请指定`application-load-balancer``Type`。  
**弹性负载均衡器**  
要将流量路由到 ELB Classic 负载均衡器，请指定`elastic-load-balancer`。`Type`  
**网络负载均衡器**  
要将流量路由到 ELB 网络负载均衡器，请指定`network-load-balancer`。`Type`  
**弹性豆茎**  
要将流量路由到 Elastic Beanstalk 环境，请指定。`elastic-beanstalk` `Type`  
**s3 网站**  
要将流量路由到配置为网站终端节点的 Amazon S3 存储桶，请指定`s3-website``Type`。

**Region**  
要将流量路由到配置为网站终端节点的 Amazon S3 存储桶，请指定您为其创建存储桶的区域`Region`。对于任何其他资源，请省略`Region`。

**值**  
指定适用的值：    
**值**  
要将流量路由到下列资源以外的资源，请指定与您为其指定的值相对应的值`RecordType`。例如，如果您为指定`RecordType`，则`A`为指定一个 IPv4 格式的 `Value` IP 地址。  
**cloudfront**  
如果您`cloudfront`为指定了`Type`，请指定在创建 CloudFront 分配时 CloudFront 分配给您的分配的域名，例如`d111111abcdef8.cloudfront.net`。  
**应用程序负载均衡器**  
如果您`application-load-balancer`为指定了`Type`，请为您的负载均衡器指定 DNS 名称。例如 `exampleAlb-1283637735.us-east-1.elb.amazonaws.com`。  
**弹性负载均衡器**  
如果您`elastic-load-balancer`为指定了`Type`，请为您的负载均衡器指定 DNS 名称。例如，使用以`dualstack`开头的值`dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com`。  
**网络负载均衡器**  
如果您`network-load-balancer`为指定了`Type`，请为您的负载均衡器指定 DNS 名称。例如 `exampleNlb-74f87b114e21682a.elb.us-east-1.amazonaws.com`。  
**弹性豆茎**  
如果您`elastic-beanstalk`为指定了域名`Type`，请为您的 Elastic Beanstalk 环境指定域名。例如 `example-beanstalk-env-1.eba-ns4qrife.us-east-1.elasticbeanstalk.com`。  
**s3 网站**  
如果您`s3-website`为指定了`Type`，请指定您的 Amazon S3 存储桶的名称，例如`example.com.s3-website-us-east-1.amazonaws.com`。  
当您基于此流量策略创建流量策略实例时，您在此处指定的存储桶必须与您在请求中指定的域名（例如 www.example.com）匹配。`Name` [CreateTrafficPolicyInstance](https://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateTrafficPolicyInstance.html)如果`Value``Name`不匹配，则 Amazon S3 将不会响应针对该域名的 DNS 查询。

## 规则定义的语法
<a name="traffic-policy-document-format-rules"></a>

根据要使用的路由策略类型，您在流量策略文档中指定的规则定义有不同的语法：故障转移、地理位置、地理位置、延迟、多值答案或加权。

**Topics**
+ [故障转移规则](#traffic-policy-document-format-rules-failover)
+ [地理定位规则](#traffic-policy-document-format-rules-geo)
+ [地理位置邻近规则](#traffic-policy-document-format-rules-geoproximity)
+ [延迟规则](#traffic-policy-document-format-rules-latency)
+ [多值答案规则](#traffic-policy-document-format-rules-multivalue-answer)
+ [加权规则](#traffic-policy-document-format-rules-weighted)

### 故障转移规则
<a name="traffic-policy-document-format-rules-failover"></a>

有关更多信息，请参阅 *Amazon Route 53 开发人员指南*中的[配置 DNS 故障转移](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-failover-configuring.html)。

```
 1. {
 2.    "RuleType": "failover",
 3.    "Primary": {
 4.       "EndpointReference | RuleReference": "{{ID that you assigned to the rule or endpoint that this rule routes traffic to}}",
 5.       "EvaluateTargetHealth": "true" | "false",
 6.       "HealthCheck": "{{optional health check ID}}"
 7.    },
 8.    "Secondary": {
 9.       "EndpointReference | RuleReference": "{{ID that you assigned to the rule or endpoint that this rule routes traffic to}}",
10.       "EvaluateTargetHealth": "true" | "false",
11.       "HealthCheck": "{{optional health check ID}}"
12.    }
13. }
```

定义故障转移规则时，需要指定以下对象：

**RuleType**  
指定 `failover`。

**小学 \| 中学**  
对于`Primary`对象，为要在相应资源可用时将流量路由到的规则或端点指定设置。  
对于`Secondary`对象，为要在主资源不可用时将流量路由到的规则或端点指定设置。

**EndpointReference \| RuleReference**  
您是要将流量路由到终端节点还是其他规则，以及您在流量策略文档其他地方为该端点或规则分配的 ID。

**EvaluateTargetHealth**  
一个布尔值，表示您是否希望 Amazon Route 53 评估终端节点的运行状况并仅将流量路由到运行状况良好的终端节点。有关更多信息，请参阅相关文档[EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

**HealthCheck**  
如果要将运行状况检查与终端节点或规则相关联，请指定运行状况检查的 ID。有关更多信息，请参阅相关文档[HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

### 地理定位规则
<a name="traffic-policy-document-format-rules-geo"></a>

添加地理定位规则时，您可以将流量策略配置为根据用户的地理位置对流量进行路由。有关更多信息，请参阅 *Amazon Route 53 开发者指南中的地理位置路*[由](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-geo)。

```
 1. {
 2.    "RuleType": "geo",
 3.    "Locations": [
 4.       {
 5.          "EndpointReference | RuleReference": "{{ID that you assigned to the rule or endpoint that this rule routes traffic to}}",
 6.          "IsDefault": "true" | "false",
 7.          "Continent": "{{continent name}},
 8.          "Country": "{{country name}},
 9.          "Subdivision": "{{subdivision name}},
10.          "EvaluateTargetHealth": "true" | "false",
11.          "HealthCheck": "{{optional health check ID}}"
12.       },
13.       ...
14.    ]
15. }
```

定义地理定位规则时，需要指定以下对象：

**RuleType**  
指定 `geo`。

**位置**  
为要将流量路由到的每个地理位置指定一组值（`EndpointReference`\| `RuleReference` `IsDefault` `Continent` `Country` `Subdivision` `EvaluateTargetHealth`、、、、、、和`HealthCheck`）。

**EndpointReference \| RuleReference**  
您是要将流量路由到终端节点还是其他规则，以及您在流量策略文档其他地方为该端点或规则分配的 ID。

**IsDefault**  
一个布尔值，用于指示这组值是否表示默认位置。如果您指定`*`为某个地理位置中`CountryCode`元素的值，则`True`默认情况下，该位置的`IsDefault`元素值将设置为，并且您不能根据相同的地理位置规则将该`IsDefault`元素的值指定`True`为其他地理位置的元素值。有关指定`*`为`CountryCode`元素值的更多信息，请参阅以下条目`Continent, Country, Subdivision`。

**大陆、国家、分区**  
表示您要将其流量路由到规则或端点的用户的地理位置的值。有关更多信息，请参阅相关文档中的以下元素描述 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)：  
+ `GeoLocation`
+ `ContinentCode`
+ `CountryCode`
+ `SubdivisionCode`
有关更多信息，请参阅 *Amazon Route 53* 开发者指南中的[位置](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-geo.html#rrsets-values-geo-location)。  
地理位置路由的工作原理是将 IP 地址映射到位置。但是，有些 IP 地址未映射到地理位置，因此，即使您创建了覆盖所有七大洲的地理位置，Route 53 也会收到一些来自它无法识别的位置的 DNS 查询。我们建议您创建一个值为的地理位置`*`。`Country`两组查询会路由到您在此记录中指定的资源：来自您尚未为其创建地理位置的位置的查询，以及来自未映射到某个位置的 IP 地址的查询。如果您不创建`*`地理位置，Route 53 会针对来自未映射位置的查询返回 “无答案” 响应。

**EvaluateTargetHealth**  
一个布尔值，表示您是否希望 Amazon Route 53 评估终端节点的运行状况并仅将流量路由到运行状况良好的终端节点。有关更多信息，请参阅相关文档[EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

**HealthCheck**  
如果要将运行状况检查与终端节点或规则相关联，请指定运行状况检查的 ID。有关更多信息，请参阅相关文档[HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

### 地理位置邻近规则
<a name="traffic-policy-document-format-rules-geoproximity"></a>

添加地理邻近性规则时，您可以将 Amazon Route 53 配置为根据资源的地理位置将流量路由到您的资源。您也可以选择通过指定偏差将更多或更少的流量路由到给定的端点或规则。您可以使用偏差来扩大或缩小流量从中路由到终端节点或规则的地理区域的大小。有关更多信息，请参阅 *Amazon Route 53 开发者指南中的邻近地理路*[由](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-geoproximity)。

以下示例`AWSPolicyFormatVersion 2023-05-09`仅适用于：

```
 1. {
 2.    "RuleType": "geoproximity",
 3.    "GeoproximityLocations": [
 4.       { 
 5.          "EndpointReference | RuleReference": "ID that you assigned to the endpoint or rule that this rule routes traffic to",
 6.          "Location":{
 7.             "Type": "Region | LocalZone",
 8.             "LocationName": "AWS Region | AWS Local Zone"
 9.          },
10.          "Bias": "optional value to expand or shrink the geographic region for this rule, -99 to 99",
11.          "EvaluateTargetHealth": "true | false",
12.          "HealthCheck": "optional health check ID"
13.       },
14.       {
15.          "EndpointReference | RuleReference": "ID that you assigned to the endpoint or rule that this rule routes traffic to",
16.          "Location":{
17.             "Type": "Coordinate",
18.             "Latitude": "location south (negative) or north (positive) of the equator, -90 to 90 degrees",
19.             "Longitude": "location west (negative) or east (positive) of the prime meridian, -180 to 180 degrees"
20.          },
21.          "Bias": "optional value to expand or shrink the geographic region for this rule, -99 to 99",
22.          "EvaluateTargetHealth": "true | false",
23.          "HealthCheck": "optional health check ID"
24.       }
25.    ]
26. }
```

以下示例`AWSPolicyFormatVersion 2015-10-01`仅适用于：

```
 1. {
 2.    "RuleType": "geoproximity",
 3.    "GeoproximityLocations": [
 4.       {
 5.          "EndpointReference | RuleReference": "{{ID that you assigned to the endpoint or rule that this rule routes traffic to}}",
 6.          "Region": "{{AWS Region}}",
 7.          "Bias": "{{optional value to expand or shrink the geographic region for this rule, -99 to 99}}",
 8.          "EvaluateTargetHealth": "true | false",
 9.          "HealthCheck": "{{optional health check ID}}"
10.       },
11.       {
12.          "EndpointReference | RuleReference": "{{ID that you assigned to the endpoint or rule that this rule routes traffic to}}",
13.          "Latitude": "{{location south (negative) or north (positive) of the equator, -90 to 90 degrees}}",
14.          "Longitude": "{{location west (negative) or east (positive) of the prime meridian, -180 to 180 degrees}}",
15.          "Bias": "{{optional value to expand or shrink the geographic region for this rule, -99 to 99}}",
16.          "EvaluateTargetHealth": "true | false",
17.          "HealthCheck": "{{optional health check ID}}"
18.       }
19.    ]
20. }
```

在定义地理邻近度规则时，需要指定以下对象：

**RuleType**  
指定 `geoproximity`。

**GeoproximityLocations**  
为要将流量路由到的每个资源指定一组值。您可以指定**位置**字段，该字段支持 AWS Regions、Local Zones 以及中的纬度和经度。`AWSPolicyFormatVersion 2023-05-09`您还可以在中指定 AWS 区域或地理位置的纬度和经度。`AWSPolicyFormatVersion 2015-10-01`

**EndpointReference \| RuleReference**  
您是要将流量路由到终端节点还是其他规则，以及您在流量策略文档其他地方为该端点或规则分配的 ID。

**地点（`AWSPolicyFormatVersion 2023-05-09`仅限）**  
Location 字段支持 AWS 区域、Local Zones 以及纬度和经度，格式如下：  
对于 Local Zones：`"Location": { "Type": "LocalZone", "LocationName": "aws:route53:us-east-1-atl-1a" }`  
对于区域：`"Location": { "Type": "Region", "LocationName": "aws:route53:us-east-1" },`  
对于坐标：`"Location": { "Type": "Coordinate", "Latitude": "38.9", "Longitude": "-77.01" },`  
有关有效区域代码的列表，请参阅相关文档中的[区域[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-Region)。  
有关可用的 Local Zones，请参阅 [AWS Local Zones 位置](https://aws.amazon.com/about-aws/global-infrastructure/localzones/locations/)。

**区域（`AWSPolicyFormatVersion 2015-10-01`仅限）**  
如果您的终端节点是 AWS 资源，请指定您在其中创建资源的 AWS 区域。采用以下格式：  
`aws:route53:`{{region-code}}  
有关有效区域代码的列表，请参阅相关文档中的[区域[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-Region)。

**纬度和经度（`AWSPolicyFormatVersion 2015-10-01`仅限）**  
如果您的终端节点不是 AWS 资源，请输入资源所在位置的纬度和经度。注意以下几点：  
+ 纬度代表赤道以南 (负) 或以北 (正) 的位置。有效值为 -90 度到 90 度。
+ 经度代表主子午线以西 (负) 或以东 (正) 的位置。有效值为 -180 度到 180 度。
+ 您可以从一些联机映射应用程序中获得纬度和经度。例如，在 Google 地图中，位置的 URL 指定了纬度和经度：

  https://www.google.com/maps/**@ **47.6086** 111，-122.3409953,20z**
+ 例如，您最多可以输入两位小数点的精度。`47.61`如果您指定的值精度更高，则 Route 53 会返回错误。对于赤道处的纬度和经度，0.01 度大约是 0.69 英里。

**偏差**  
`Bias`如果要将更多流量从附近的终端节点路由到终端节点（正值）或将较少的流量路由到终端节点（负值），请为指定一个值。有效值范围为 -99 到 99；默认值为 0。  
的值`Bias`是基于其他资源位置的相对值，而不是基于距离的绝对值。因此，更改的影响是难以预测的。例如，根据您的资源所在的位置，将偏差从更改`10`为`15`可能意味着增加或减少来自纽约市都会区的大量流量。我们建议您以较小的增量更改偏差并对结果进行评估，然后进行其他更改 (如果适用)。

**EvaluateTargetHealth**  
一个布尔值，表示您是否希望 Route 53 评估终端节点的运行状况并仅将流量路由到健康的终端节点。有关更多信息，请参阅相关文档[EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

**HealthCheck**  
如果要将运行状况检查与终端节点或规则相关联，请指定运行状况检查的 ID。有关更多信息，请参阅相关文档[HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

### 延迟规则
<a name="traffic-policy-document-format-rules-latency"></a>

添加延迟规则时，您可以配置流量策略，根据用户与创建 AWS 资源（例如 ELB 负载均衡器和 Amazon S3 存储桶）的 AWS 区域之间的延迟（时间延迟）来路由流量。有关更多信息，请参阅 *Amazon Route 53 开发人员指南中的延迟路*[由](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-latency)。

```
 1. {
 2.    "RuleType": "latency",
 3.    "Regions": [
 4.       {
 5.          "EndpointReference | RuleReference": "{{ID that you assigned to the rule or endpoint that this rule routes traffic to}}",
 6.          "Region": "{{AWS region that you want to route traffic to}}",
 7.          "EvaluateTargetHealth": "true" | "false",
 8.          "HealthCheck": "{{optional health check ID}}"
 9.       },
10.       ...
11.    ]
12. }
```

在定义延迟规则时，需要指定以下对象：

**RuleType**  
指定 `latency`。

**Regions**  
为要将流量路由到的每个区域指定一组值（`EndpointReference`\| `RuleReference` `EvaluateTargetHealth`、、和`HealthCheck`）。`Region`

**EndpointReference \| RuleReference**  
您是要将流量路由到终端节点还是其他规则，以及您在流量策略文档其他地方为该端点或规则分配的 ID。

**Region**  
您在其中创建资源的 AWS 区域的区域代码。有关有效区域代码的列表，请参阅相关文档中的[区域[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-Region)。

**EvaluateTargetHealth**  
一个布尔值，表示您是否希望 Amazon Route 53 评估终端节点的运行状况并仅将流量路由到运行状况良好的终端节点。有关更多信息，请参阅相关文档[EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

**HealthCheck**  
如果要将运行状况检查与终端节点或规则相关联，请指定运行状况检查的 ID。有关更多信息，请参阅相关文档[HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

### 多值答案规则
<a name="traffic-policy-document-format-rules-multivalue-answer"></a>

添加多值答案规则时，您可以将流量策略配置为将流量大致随机路由到您的健康资源。Amazon Route 53 最多使用八条健康记录响应 DNS 查询；如果您的健康记录不超过八个，则 Route 53 会使用所有健康记录来响应所有 DNS 查询。有关更多信息，请参阅 [MultiValueAnswer](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-MultiValueAnswer)。

```
 1. {
 2.    "RuleType": "multivalue",
 3.    "Items": [
 4.       {
 5.          "EndpointReference": "{{ID that you assigned to the endpoint that this rule routes traffic to}}",
 6.          "HealthCheck": "{{optional health check ID}}"
 7.       },
 8.       ...
 9.    ]
10. }
```

定义多值答案规则时，需要指定以下对象：

**RuleType**  
指定 `multivalue`。

**物品**  
为要将流量路由到的每条多值答案规则或端点指定一组值（`EndpointReference`和`HealthCheck`）。

**EndpointReference**  
您在流量策略文档的其他地方分配给端点的 ID。

**HealthCheck**  
如果要将运行状况检查与终端节点关联，请指定运行状况检查的 ID。有关更多信息，请参阅 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

### 加权规则
<a name="traffic-policy-document-format-rules-weighted"></a>

添加加权规则时，您可以将流量策略配置为根据您指定的比例路由流量。例如，您可以将权重指定为 4、5、5 和 6（总和 = 20）。结果是， 4/20ths 平均而言，您的流量会路由到第一个端点或规则， 5/20ths 同时路由到第二个和第三个终端节点或规则，然后 6/20ths 路由到最后一个端点或规则。有关更多信息，请参阅 *Amazon Route 53 开发人员指南*中的[加权路由](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted)。

```
 1. {
 2.    "RuleType": "weighted",
 3.    "Items": [
 4.       {
 5.          "EndpointReference | RuleReference": "{{ID that you assigned to the rule or endpoint that this rule routes traffic to}}",
 6.          "Weight": "{{value between 0 and 255}}",
 7.          "EvaluateTargetHealth": "true" | "false",
 8.          "HealthCheck": "{{optional health check ID}}"
 9.       },
10.       ...
11.    ]
12. }
```

定义加权规则时，需要指定以下对象：

**RuleType**  
指定 `weighted`。

**物品**  
为要将流量路由到的每个加权规则或端点指定一组值（`EndpointReference`\| `RuleReference` `EvaluateTargetHealth`、、和`HealthCheck`）。`Weight`

**EndpointReference \| RuleReference**  
您是要将流量路由到终端节点还是其他规则，以及您在流量策略文档其他地方为该端点或规则分配的 ID。

**重量**  
介于 0 和 255 之间的值，用于确定路由到相应端点或规则的流量比例。有关更多信息，请参阅相关文档中的[重量[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-Weight)。

**EvaluateTargetHealth**  
一个布尔值，表示您是否希望 Amazon Route 53 评估终端节点的运行状况并仅将流量路由到运行状况良好的终端节点。有关更多信息，请参阅相关文档[EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

**HealthCheck**  
如果要将运行状况检查与终端节点或规则相关联，请指定运行状况检查的 ID。有关更多信息，请参阅相关文档[HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)中的[ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html)。

## 示例
<a name="traffic-policy-document-format-examples"></a>

以下示例说明如何使用故障转移、地理位置、地理位置、延迟和加权规则，以及如何在同一个流量策略中使用多种类型的规则。

**Topics**
+ [故障转移示例](#traffic-policy-document-format-examples-failover)
+ [地理定位示例](#traffic-policy-document-format-examples-geolocation)
+ [地理邻近示例](#traffic-policy-document-format-examples-proximity)
+ [延迟示例](#traffic-policy-document-format-examples-latency)
+ [加权示例](#traffic-policy-document-format-examples-weighted)
+ [故障转移、延迟和地理定位规则示例](#traffic-policy-document-format-examples-combined)

### 故障转移示例
<a name="traffic-policy-document-format-examples-failover"></a>

```
{
   "AWSPolicyFormatVersion":"2015-10-01",
   "RecordType":"A",
   "StartRule":"site_switch",
   "Endpoints":{
      "my_elb":{
         "Type":"elastic-load-balancer",
         "Value":"elb-111111.us-east-1.elb.amazonaws.com"
      },
      "site_down_banner":{
         "Type":"s3-website",
         "Region":"us-east-1",
         "Value":"www.example.com"
      }
   },
   "Rules":{
      "site_switch":{
         "RuleType":"failover",
         "Primary":{
            "EndpointReference":"my_elb"
         },
         "Secondary":{
            "EndpointReference":"site_down_banner"
         }
      }
   }
}
```

### 地理定位示例
<a name="traffic-policy-document-format-examples-geolocation"></a>

```
{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"geo_dest",
  "Endpoints":{
    "english":{
      "Type":"value",
      "Value":"192.0.2.1"
    },
    "french":{
      "Type":"value",
      "Value":"192.0.2.2"
    },
    "german":{
      "Type":"value",
      "Value":"192.0.2.3"
    }
  },
  "Rules":{
    "geo_dest":{
      "RuleType":"geo",
      "Locations":[
        {
          "EndpointReference":"english",
          "Country":"*",
          "HealthCheck":"11111111-1111-1111-1111-111111111111"
        },
        {
          "EndpointReference":"french",
          "Country":"FR",
          "IsDefault":false,
          "HealthCheck":"22222222-2222-2222-2222-222222222222"
        },
        {
          "EndpointReference":"french",
          "Country":"BE",
          "IsDefault":false,
          "HealthCheck":"22222222-2222-2222-2222-222222222222"
        },
        {
          "EndpointReference":"german",
          "Country":"DE",
          "IsDefault":false,
          "HealthCheck":"33333333-3333-3333-3333-333333333333"
        }
      ]
    }
  }
}
```

### 地理邻近示例
<a name="traffic-policy-document-format-examples-proximity"></a>

```
{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"geoprox-rule",
  "Endpoints":{
    "aws-us-west-1-region":{
      "Type":"elastic-load-balancer",
      "Value":"elb-123456.us-east-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"
        }
      ]
    }
  }
}
```

```
{
  "AWSPolicyFormatVersion":"2023-05-09",
  "RecordType":"A",
  "StartRule":"geoprox-rule",
  "Endpoints":{
    "aws-us-west-1-region":{
      "Type":"elastic-load-balancer",
      "Value":"elb-123456.us-west-1.elb.amazonaws.com"
    },
    "aws-us-east-1-atl-local-zone":{
      "Type":"elastic-load-balancer",
      "Value":"elb-123456.us-east-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",
          "Location": {
            "Type": "Region",
            "LocationName": "aws:route53:us-west-1"
          },
          "Bias": "-10",
          "HealthCheck": "11111111-1111-1111-1111-111111111111"
        },
        {
          "EndpointReference": "aws-us-east-1-atl-local-zone",
          "Location": {
            "Type": "LocalZone",
            "LocationName": "aws:route53:us-east-1-atl-1a"
          },
          "Bias": "10",
          "HealthCheck": "22222222-2222-2222-2222-222222222222"
        },
        {
          "EndpointReference": "london-data-center",
          "Location": {
            "Type": "Coordinate",
            "Latitude": "51.50",
            "Longitude": "-0.16"
          },
          "Bias": "0",
          "HealthCheck": "33333333-3333-3333-3333-333333333333"
        }
      ]
    }
  }
}
```

### 延迟示例
<a name="traffic-policy-document-format-examples-latency"></a>

```
{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"region_selector",
  "Endpoints":{
    "us_lb":{
      "Type":"elastic-load-balancer",
      "Value":"elb-123456.us-east-1.elb.amazonaws.com"
    },
    "europe_lb":{
      "Type":"elastic-load-balancer",
      "Value":"elb-654321.eu-west-1.elb.amazonaws.com"
    }
  },
  "Rules":{
    "region_selector":{
      "RuleType":"latency",
      "Regions":[
        {
          "Region":"us-east-1",
          "EndpointReference":"us_lb"
        },
        {
          "Region":"eu-west-1",
          "EndpointReference":"europe_lb"
        }
      ]
    }
  }
}
```

### 加权示例
<a name="traffic-policy-document-format-examples-weighted"></a>

```
{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"round_robin",
  "Endpoints":{
    "srv1":{
      "Type":"value",
      "Value":"192.0.2.1"
    },
    "srv2":{
      "Type":"value",
      "Value":"192.0.2.2"
    },
    "srv3":{
      "Type":"value",
      "Value":"192.0.2.3"
    }
  },
  "Rules":{
    "round_robin":{
      "RuleType":"weighted",
      "Items":[
        {
          "EndpointReference":"srv1",
          "Weight":"3",
          "HealthCheck":"11111111-1111-1111-1111-111111111111"
        },
        {
          "EndpointReference":"srv2",
          "Weight":"1",
          "HealthCheck":"22222222-2222-2222-2222-222222222222"
        },
        {
          "EndpointReference":"srv3",
          "Weight":"1",
          "HealthCheck":"33333333-3333-3333-3333-333333333333"
        }
      ]
    }
  }
}
```

### 故障转移、延迟和地理定位规则示例
<a name="traffic-policy-document-format-examples-combined"></a>

```
{
  "AWSPolicyFormatVersion":"2015-10-01",
  "RecordType":"A",
  "StartRule":"geo_restriction",
  "Endpoints":{
    "east_coast_lb1":{
      "Type":"elastic-load-balancer",
      "Value":"elb-111111.us-east-1.elb.amazonaws.com"
    },
    "east_coast_lb2":{
      "Type":"elastic-load-balancer",
      "Value":"elb-222222.us-east-1.elb.amazonaws.com"
    },
    "west_coast_lb1":{
      "Type":"elastic-load-balancer",
      "Value":"elb-111111.us-west-1.elb.amazonaws.com"
    },
    "west_coast_lb2":{
      "Type":"elastic-load-balancer",
      "Value":"elb-222222.us-west-1.elb.amazonaws.com"
    },
    "denied_message":{
      "Type":"s3-website",
      "Region":"us-east-1",
      "Value":"video.example.com"
    }
  },
  "Rules":{
    "geo_restriction":{
      "RuleType":"geo",
      "Locations":[
        {
          "EndpointReference":"denied_message",
          "IsDefault":true
        },
        {
          "RuleReference":"region_selector",
          "Country":"US"
        }
      ]
    },
    "region_selector":{
      "RuleType":"latency",
      "Regions":[
        {
          "Region":"us-east-1",
          "RuleReference":"east_coast_region"
        },
        {
          "Region":"us-west-1",
          "RuleReference":"west_coast_region"
        }
      ]
    },
    "east_coast_region":{
      "RuleType":"failover",
      "Primary":{
        "EndpointReference":"east_coast_lb1"
      },
      "Secondary":{
        "EndpointReference":"east_coast_lb2"
      }
    },
    "west_coast_region":{
      "RuleType":"failover",
      "Primary":{
        "EndpointReference":"west_coast_lb1"
      },
      "Secondary":{
        "EndpointReference":"west_coast_lb2"
      }
    }
  }
}
```