

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

當您使用其中一個 AWS SDKs、 AWS CLI或 Amazon Route 53 API，以程式設計方式建立流量政策時 AWS Tools for Windows PowerShell，請以 JSON 格式的 `Document`元素指定流量政策的定義。

如需流量政策的詳細資訊，請參閱《*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**  
流量政策格式的版本，支援 AWS Local Zones 的最新版本；`2023-05-09`。  
也支援舊版；`2015-10-01`。

**RecordType**  
Amazon Route 53 將根據此流量政策建立的所有資源紀錄集的 DNS 類型。如果您想要將流量路由到下列 AWS 資源，請選擇適用的值：  
+ **CloudFront 分佈**：選擇 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **ELB Application Load Balancer**：選擇 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **ELB Classic Load Balancer**：選擇 **A：IPv4 格式的 IP 地址**或 **AAAA：IPv6 格式的 IP 地址**。
+ **ELB Network Load Balancer**：選擇 **A：IPv4 格式的 IP 地址** 或 **AAAA：IPv6 格式的 IP 地址**。
+ **Elastic Beanstalk 環境** – 選擇 **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)。

**規則**  
您想要在此流量政策中使用的規則定義。如需詳細資訊，請參閱[規則定義的語法](#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**  
若要將流量路由到下列清單中資源以外的資源，請`value`為 指定 `Type`。  
**cloudfront**  
若要將流量路由到 CloudFront 分佈，請`cloudfront`為 指定 `Type`。  
**application-load-balancer**  
若要將流量路由到 Application Load Balancer，請`application-load-balancer`為 指定 `Type`。  
**elastic-load-balancer**  
若要將流量路由到 ELB Classic 負載平衡器，請`elastic-load-balancer`為 指定 `Type`。  
**network-load-balancer**  
若要將流量路由到 ELB 網路負載平衡器，請`network-load-balancer`為 指定 `Type`。  
**elastic-beanstalk**  
若要將流量路由到 Elastic Beanstalk 環境，請`elastic-beanstalk`為 指定 `Type`。  
**s3-website**  
若要將流量路由到設定為網站端點的 Amazon S3 儲存貯體，請`s3-website`為 指定 `Type`。

**區域**  
若要將流量路由到設定為網站端點的 Amazon S3 儲存貯體，請指定您為 建立儲存貯體的區域`Region`。對於任何其他資源，請省略 `Region`。

**Value**  
指定適用的值：    
**value**  
若要將流量路由到下列資源以外的資源，請指定對應至您為 指定的值的值`RecordType`。例如，如果您`A`為 指定 `RecordType`，請為 指定 IPv4 格式的 IP 地址`Value`。  
**cloudfront**  
如果您`cloudfront`為 指定 `Type`，請指定 CloudFront 在您建立 CloudFront 分佈時指派給 CloudFront 分佈的網域名稱，例如 `d111111abcdef8.cloudfront.net`。  
**application-load-balancer**  
如果您`application-load-balancer`為 指定 `Type`，請指定負載平衡器的 DNS 名稱。例如 `exampleAlb-1283637735.us-east-1.elb.amazonaws.com`。  
**elastic-load-balancer**  
如果您`elastic-load-balancer`為 指定 `Type`，請指定負載平衡器的 DNS 名稱。使用開頭為 的值`dualstack`，例如 `dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com`。  
**network-load-balancer**  
如果您`network-load-balancer`為 指定 `Type`，請指定負載平衡器的 DNS 名稱。例如 `exampleNlb-74f87b114e21682a.elb.us-east-1.amazonaws.com`。  
**elastic-beanstalk**  
如果您`elastic-beanstalk`為 指定 `Type`，請指定 Elastic Beanstalk 環境的網域名稱。例如 `example-beanstalk-env-1.eba-ns4qrife.us-east-1.elasticbeanstalk.com`。  
**s3-website**  
如果您`s3-website`為 指定 `Type`，請指定 Amazon S3 儲存貯體的名稱，例如 `example.com.s3-website-us-east-1.amazonaws.com`。  
當您根據此流量政策建立流量政策執行個體時，您在此處指定的儲存貯體必須符合您在 [CreateTrafficPolicyInstance](https://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateTrafficPolicyInstance.html) 請求`Name`中為 指定的網域名稱 （例如 www.example.com)。如果 `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 評估端點的運作狀態，並將流量僅路由至運作狀態良好的端點。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)。

**HealthCheck**  
如果您想要將運作狀態檢查與端點或規則建立關聯，請指定運作狀態檢查的 ID。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

### 地理位置規則
<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`。

**位置**  
針對您要將流量路由到的每個地理位置`Subdivision`，指定一組值 `Country`(`EndpointReference` \| `RuleReference``IsDefault`、`Continent`、`EvaluateTargetHealth`、、 和 `HealthCheck`)。

**EndpointReference \| RuleReference**  
無論您想要將流量路由到端點或另一個規則，以及您在流量政策文件中其他位置指派給端點或規則的 ID。

**IsDefault**  
布林值，指出這組值是否代表預設位置。如果您將 指定`*`為地理位置中 `CountryCode`元素的值，則此位置的 `IsDefault`元素值`True`預設為 ，而且您無法將 指定`True`為相同地理位置規則在其他地理位置中 `IsDefault`元素的值。如需將 指定`*`為 `CountryCode`元素值的詳細資訊，請參閱 的下列項目`Continent, Country, Subdivision`。

**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 評估端點的運作狀態，並將流量僅路由至運作狀態良好的端點。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)。

**HealthCheck**  
如果您想要將運作狀態檢查與端點或規則建立關聯，請指定運作狀態檢查的 ID。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

### 地理位置鄰近性規則
<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 區域、本地區域和經度`AWSPolicyFormatVersion 2023-05-09`。您也可以在 中指定 AWS 區域或地理位置的經緯度`AWSPolicyFormatVersion 2015-10-01`。

**EndpointReference \| RuleReference**  
無論您想要將流量路由到端點或另一個規則，以及您在流量政策文件中其他位置指派給端點或規則的 ID。

**位置 (`AWSPolicyFormatVersion 2023-05-09`僅限 )**  
位置欄位支援 AWS 區域、本地區域和經度，格式如下：  
對於本機區域： `"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 Zone，請參閱 [AWS Local Zones locations](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 Maps，位置的 URL 指定經緯度：

  https://www.google.com/maps/@**47.6086111**,-**122.3409953**,20z
+ 您可以輸入最多兩個十進位的精確度，例如 `47.61`。如果您指定精確度更高的值，Route 53 會傳回錯誤。對於赤道處的緯度和經度，0.01 度大約是 0.69 英里。

**偏差**  
`Bias` 如果您想要將更多流量從附近的端點 （正值） 路由到端點，或將較少流量路由到端點 （負值），請指定 的值。有效值的範圍是 -99 到 99；預設值為 0。  
的值`Bias`是相對的，根據其他資源的位置，而不是絕對，根據距離。因此，變更的效果難以預測。例如，根據您的資源所在位置，將偏差從 `10` 變更為 `15`可能意味著從紐約市都會區域新增或減去大量流量之間的差異。我們建議您以較小的增量變更偏差並對結果進行評估，然後進行其他變更 (如果適用)。

**EvaluateTargetHealth**  
布林值，指出您是否希望 Route 53 評估端點的運作狀態，並將流量僅路由至運作狀態良好的端點。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)。

**HealthCheck**  
如果您想要將運作狀態檢查與端點或規則建立關聯，請指定運作狀態檢查的 ID。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

### 延遲規則
<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`、、 `Region`和 `HealthCheck`)。

**EndpointReference \| RuleReference**  
無論您想要將流量路由到端點或另一個規則，以及您在流量政策文件中其他位置指派給端點或規則的 ID。

**區域**  
您建立資源所在 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 評估端點的運作狀態，並將流量僅路由至運作狀態良好的端點。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)。

**HealthCheck**  
如果您想要將運作狀態檢查與端點或規則建立關聯，請指定運作狀態檢查的 ID。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

### 多值回答規則
<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/20 的流量路由到第一個端點或規則，5/20 同時路由到第二個和第三個端點或規則，而 6/20 路由到最後一個端點或規則。如需詳細資訊，請參閱《*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`、、 `Weight`和 `HealthCheck`)。

**EndpointReference \| RuleReference**  
無論您想要將流量路由到端點或另一個規則，以及您在流量政策文件中其他位置指派給端點或規則的 ID。

**Weight (粗細)**  
介於 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 評估端點的運作狀態，並將流量僅路由至運作狀態良好的端點。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [EvaluateTargetHealth](https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html#Route53-Type-AliasTarget-EvaluateTargetHealth)。

**HealthCheck**  
如果您想要將運作狀態檢查與端點或規則建立關聯，請指定運作狀態檢查的 ID。如需詳細資訊，請參閱 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) 文件中的 [HealthCheckId](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ResourceRecordSet.html#Route53-Type-ResourceRecordSet-HealthCheckId)。

## 範例
<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"
      }
    }
  }
}
```