使用 53 號路線示例 AWS CLI - AWS Command Line Interface

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

使用 53 號路線示例 AWS CLI

下列程式碼範例會示範如何使用 Route 53 來執行動作及實作常見案例。 AWS Command Line Interface

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境和跨服務範例中查看內容中的動作。

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用change-resource-record-sets

AWS CLI

建立、更新或刪除資源記錄集的步驟

下列change-resource-record-sets命令會使用hosted-zone-idZ1R8UBAEXAMPLE和檔案中 JSON 格式的組態建立資源記錄集:C:\awscli\route53\change-resource-record-sets.json

aws route53 change-resource-record-sets --hosted-zone-id Z1R8UBAEXAMPLE --change-batch file://C:\awscli\route53\change-resource-record-sets.json

如需詳細資訊,請參閱 Amazon Route 53 API 參考 ChangeResourceRecordSets 中的 POST。

JSON 檔案中的配置取決於您要建立的資源記錄集類型:

BasicWeightedAliasWeighted AliasLatencyLatency AliasFailoverFailover 別名

基本語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ] } }, {...} ] }

加權語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Weight": value between 0 and 255, "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

別名語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

加權別名語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Weight": value between 0 and 255, "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

延遲語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Region": "Amazon EC2 region name", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

延遲別名語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Region": "Amazon EC2 region name", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

容錯移轉語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Failover": "PRIMARY" | "SECONDARY", "TTL": time to live in seconds, "ResourceRecords": [ { "Value": "applicable value for the record type" }, {...} ], "HealthCheckId": "ID of an Amazon Route 53 health check" } }, {...} ] }

容錯移轉別名語法

{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE"|"DELETE"|"UPSERT", "ResourceRecordSet": { "Name": "DNS domain name", "Type": "SOA"|"A"|"TXT"|"NS"|"CNAME"|"MX"|"PTR"|"SRV"|"SPF"|"AAAA", "SetIdentifier": "unique description for this resource record set", "Failover": "PRIMARY" | "SECONDARY", "AliasTarget": { "HostedZoneId": "hosted zone ID for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or Amazon Route 53 hosted zone", "DNSName": "DNS domain name for your CloudFront distribution, Amazon S3 bucket, Elastic Load Balancing load balancer, or another resource record set in this hosted zone", "EvaluateTargetHealth": true|false }, "HealthCheckId": "optional ID of an Amazon Route 53 health check" } }, {...} ] }

下列程式碼範例會示範如何使用change-tags-for-resource

AWS CLI

下列命令會將名為的標籤新增owner至由 ID 指定的健康狀態檢查資源:

aws route53 change-tags-for-resource --resource-type healthcheck --resource-id 6233434j-18c1-34433-ba8e-3443434 --add-tags Key=owner,Value=myboss

下列命令會owner從 ID 指定的託管區域資源中移除名為的標籤:

aws route53 change-tags-for-resource --resource-type hostedzone --resource-id Z1523434445 --remove-tag-keys owner

下列程式碼範例會示範如何使用create-health-check

AWS CLI

建立健康狀態檢查的步驟

下列create-health-check命令會使用呼叫者參考2014-04-01-18:47和檔案中 JSON 格式的組態來建立健康狀態檢查:C:\awscli\route53\create-health-check.json

aws route53 create-health-check --caller-reference 2014-04-01-18:47 --health-check-config file://C:\awscli\route53\create-health-check.json

JSON 語法:

{ "IPAddress": "IP address of the endpoint to check", "Port": port on the endpoint to check--required when Type is "TCP", "Type": "HTTP"|"HTTPS"|"HTTP_STR_MATCH"|"HTTPS_STR_MATCH"|"TCP", "ResourcePath": "path of the file that you want Amazon Route 53 to request--all Types except TCP", "FullyQualifiedDomainName": "domain name of the endpoint to check--all Types except TCP", "SearchString": "if Type is HTTP_STR_MATCH or HTTPS_STR_MATCH, the string to search for in the response body from the specified resource", "RequestInterval": 10 | 30, "FailureThreshold": integer between 1 and 10 }

若要將健全狀況檢查新增至 Route 53 資源記錄集,請使用change-resource-record-sets指令。

如需詳細資訊,請參閱 Amazon Route 53 開發人員指南中的 Amazon Route 53 運作 Health 態檢查和 DNS 備援。

下列程式碼範例會示範如何使用create-hosted-zone

AWS CLI

若要建立託管區域

下列create-hosted-zone命令會新增example.com使用呼叫者參考命名的託管區域2014-04-01-18:47。可選註釋包括一個空格,因此必須用引號括起來:

aws route53 create-hosted-zone --name example.com --caller-reference 2014-04-01-18:47 --hosted-zone-config Comment="command-line version"

如需詳細資訊,請參閱 Amazon Route 53 開發人員指南中的使用託管區域。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateHostedZone中的。

下列程式碼範例會示範如何使用delete-health-check

AWS CLI

若要刪除健全狀態檢查

下列delete-health-check命令會刪除運作狀態檢查,其中包health-check-ide75b48d9-547a-4c3d-88a5-ae4002397608

aws route53 delete-health-check --health-check-id e75b48d9-547a-4c3d-88a5-ae4002397608

下列程式碼範例會示範如何使用delete-hosted-zone

AWS CLI

刪除託管區域

下列delete-hosted-zone指令會刪除具有下列項目id的託管區域Z36KTIQEXAMPLE

aws route53 delete-hosted-zone --id Z36KTIQEXAMPLE
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteHostedZone中的。

下列程式碼範例會示範如何使用get-change

AWS CLI

若要取得資源記錄集變更的狀態,請執行下列步驟:

下列get-change命令會取得有關具有Idchange-resource-record-sets要求的狀態和其他資訊/change/CWPIK4URU2I5S

aws route53 get-change --id /change/CWPIK4URU2I5S
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetChange中的。

下列程式碼範例會示範如何使用get-health-check

AWS CLI

取得有關健康狀態檢查的資訊

下列get-health-check命令會取得具有的健全狀況檢查health-check-id的相關資訊02ec8401-9879-4259-91fa-04e66d094674

aws route53 get-health-check --health-check-id 02ec8401-9879-4259-91fa-04e66d094674
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetHealthCheck中的。

下列程式碼範例會示範如何使用get-hosted-zone

AWS CLI

取得託管區域的相關資訊

以下get-hosted-zone命令使用以下命令獲取託管區域id的相關信息Z1R8UBAEXAMPLE

aws route53 get-hosted-zone --id Z1R8UBAEXAMPLE
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetHostedZone中的。

下列程式碼範例會示範如何使用list-health-checks

AWS CLI

若要列出與目前 AWS 帳戶相關聯的健全狀態檢查

下列list-health-checks命令會列出與目前 AWS 帳戶相關聯的前 100 個健全狀況檢查的詳細資訊。 :

aws route53 list-health-checks

如果您有超過 100 項健康狀態檢查,或者您想要以小於 100 的群組列出這些檢查,請包括--maxitems參數。例如,若要一次列出一個健康狀態檢查,請使用下列命令:

aws route53 list-health-checks --max-items 1

若要檢視下一個健康狀態檢查,請NextToken從上一個命令的回應中取得的值,並將其包含在--starting-token參數中,例如:

aws route53 list-health-checks --max-items 1 --starting-token Z3M3LMPEXAMPLE
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListHealthChecks中的。

下列程式碼範例會示範如何使用list-hosted-zones-by-name

AWS CLI

下列命令列出最多 100 個依網域名稱排序的託管區域:

aws route53 list-hosted-zones-by-name

輸出:

{ "HostedZones": [ { "ResourceRecordSetCount": 2, "CallerReference": "test20150527-2", "Config": { "Comment": "test2", "PrivateZone": false }, "Id": "/hostedzone/Z119WBBTVP5WFX", "Name": "2.example.com." }, { "ResourceRecordSetCount": 2, "CallerReference": "test20150527-1", "Config": { "Comment": "test", "PrivateZone": false }, "Id": "/hostedzone/Z3P5QSUBK4POTI", "Name": "www.example.com." } ], "IsTruncated": false, "MaxItems": "100" }

以下命令列出按名稱排序的託管區域,開頭為www.example.com

aws route53 list-hosted-zones-by-name --dns-name www.example.com

輸出:

{ "HostedZones": [ { "ResourceRecordSetCount": 2, "CallerReference": "mwunderl20150527-1", "Config": { "Comment": "test", "PrivateZone": false }, "Id": "/hostedzone/Z3P5QSUBK4POTI", "Name": "www.example.com." } ], "DNSName": "www.example.com", "IsTruncated": false, "MaxItems": "100" }

下列程式碼範例會示範如何使用list-hosted-zones

AWS CLI

列出與目前 AWS 帳號相關聯的託管區域

下列list-hosted-zones命令列出與目前 AWS 帳戶相關聯的前 100 個託管區域的摘要資訊。 :

aws route53 list-hosted-zones

如果您具有 100 個以上的託管區域,或者要以小於 100 的群組列示它們,請包括 --max-items 參數。例如,若要一次列出一個託管區域,請使用下列命令:

aws route53 list-hosted-zones --max-items 1

若要檢視有關下一個託管區域的資訊,請從上一個命令的回應中取得 NextToken 值,並將其包含在 --starting-token 參數中,例如:

aws route53 list-hosted-zones --max-items 1 --starting-token Z3M3LMPEXAMPLE
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListHostedZones中的。

下列程式碼範例會示範如何使用list-query-logging-configs

AWS CLI

若要列出查詢記錄組態

下列list-query-logging-configs範例會針對託管區域,列出 AWS 帳戶中前 100 個查詢記錄設定的相關資訊Z1OX3WQEXAMPLE

aws route53 list-query-logging-configs \ --hosted-zone-id Z1OX3WQEXAMPLE

輸出:

{ "QueryLoggingConfigs": [ { "Id": "964ff34e-ae03-4f06-80a2-9683cexample", "HostedZoneId": "Z1OX3WQEXAMPLE", "CloudWatchLogsLogGroupArn": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/route53/example.com:*" } ] }

如需詳細資訊,請參閱 Amazon Route 53 開發人員指南中的記錄 DNS 查詢

下列程式碼範例會示範如何使用list-resource-record-sets

AWS CLI

列出託管區域中的資源記錄集

下列list-resource-record-sets命令列出指定託管區域中前 100 個資源記錄集的摘要資訊。 :

aws route53 list-resource-record-sets --hosted-zone-id Z2LD58HEXAMPLE

如果託管區域包含 100 個以上的資源記錄集,或者您要以小於 100 的群組列示它們,請包括--maxitems參數。例如,若要一次列出一個資源記錄集,請使用下列命令:

aws route53 list-resource-record-sets --hosted-zone-id Z2LD58HEXAMPLE --max-items 1

若要檢視有關託管區域中下一個資源記錄集的資訊,請NextToken從對上一個指令的回應中取得的值,並將其包含在--starting-token參數中,例如:

aws route53 list-resource-record-sets --hosted-zone-id Z2LD58HEXAMPLE --max-items 1 --starting-token Z3M3LMPEXAMPLE

若要檢視特定名稱的所有資源記錄集,請使用--query參數將其篩選掉。例如:

aws route53 list-resource-record-sets --hosted-zone-id Z2LD58HEXAMPLE --query "ResourceRecordSets[?Name == 'example.domain.']"