本文档仅适用于 Amazon CLI 版本 1。有关 Amazon CLI 版本 2 的相关文档,请参阅版本 2 用户指南。
使用 Amazon CLI 的 Route 53 示例
以下代码示例演示了如何通过将 Amazon Command Line Interface与 Route 53 结合使用,来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 change-resource-record-sets。
- Amazon CLI
-
创建、更新或删除资源记录集
以下
change-resource-record-sets命令使用hosted-zone-idZ1R8UBAEXAMPLE以及C:\awscli\route53\change-resource-record-sets.json文件中的 JSON 格式配置创建资源记录集:aws route53 change-resource-record-sets --hosted-zone-idZ1R8UBAEXAMPLE--change-batch file://C:\awscli\route53\change-resource-record-sets.json有关更多信息,请参阅《Amazon Route 53 API 参考》中的“POST ChangeResourceRecordSets”。
JSON 文件中的配置取决于要创建的资源记录集的类型:
BasicWeightedAliasWeighted AliasLatencyLatency AliasFailoverFailover Alias
基本语法:
{ "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" } }, {...} ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ChangeResourceRecordSets
。
-
以下代码示例演示了如何使用 change-tags-for-resource。
- Amazon CLI
-
以下命令将名为
owner的标签添加到由 ID 指定的运行状况检查资源:aws route53 change-tags-for-resource --resource-typehealthcheck--resource-id6233434j-18c1-34433-ba8e-3443434--add-tagsKey=owner,Value=myboss以下命令将从由 ID 指定的托管区资源中移除名为
owner的标签:aws route53 change-tags-for-resource --resource-typehostedzone--resource-idZ1523434445--remove-tag-keysowner-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ChangeTagsForResource
。
-
以下代码示例演示了如何使用 create-health-check。
- Amazon CLI
-
创建运行状况检查
以下
create-health-check命令使用调用方参考2014-04-01-18:47和文件C:\awscli\route53\create-health-check.json中的 JSON 格式配置创建运行状况检查:aws route53 create-health-check --caller-reference2014-04-01-18:47--health-check-config file://C:\awscli\route53\create-health-check.jsonJSON 语法:
{ "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 运行状况检查和 DNS 故障转移”。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateHealthCheck
。
-
以下代码示例演示了如何使用 create-hosted-zone。
- Amazon CLI
-
创建托管区
以下
create-hosted-zone命令使用调用方参考2014-04-01-18:47添加名为example.com的托管区。可选注释中包含一个空格,因此必须用引号括起来:aws route53 create-hosted-zone --nameexample.com--caller-reference2014-04-01-18:47--hosted-zone-config Comment="command-line version"有关更多信息,请参阅《Amazon Route 53 开发人员指南》中的“使用托管区”。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateHostedZone
。
-
以下代码示例演示了如何使用 delete-health-check。
- Amazon CLI
-
删除运行状况检查
以下
delete-health-check命令将删除health-check-id为e75b48d9-547a-4c3d-88a5-ae4002397608的运行状况检查:aws route53 delete-health-check --health-check-ide75b48d9-547a-4c3d-88a5-ae4002397608-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteHealthCheck
。
-
以下代码示例演示了如何使用 delete-hosted-zone。
- Amazon CLI
-
删除托管区
以下
delete-hosted-zone命令将删除id为Z36KTIQEXAMPLE的托管区:aws route53 delete-hosted-zone --idZ36KTIQEXAMPLE-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteHostedZone
。
-
以下代码示例演示了如何使用 get-change。
- Amazon CLI
-
获取资源记录集更改的状态
以下
get-change命令获取Id为/change/CWPIK4URU2I5S的change-resource-record-sets请求的状态和其他信息:aws route53 get-change --id/change/CWPIK4URU2I5S-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetChange
。
-
以下代码示例演示了如何使用 get-health-check。
- Amazon CLI
-
获取有关运行状况检查的信息
以下
get-health-check命令获取有关health-check-id为02ec8401-9879-4259-91fa-04e66d094674的运行状况检查的信息:aws route53 get-health-check --health-check-id02ec8401-9879-4259-91fa-04e66d094674-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetHealthCheck
。
-
以下代码示例演示了如何使用 get-hosted-zone。
- Amazon CLI
-
获取有关托管区的信息
以下
get-hosted-zone命令获取id为Z1R8UBAEXAMPLE的托管区的相关信息:aws route53 get-hosted-zone --idZ1R8UBAEXAMPLE-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetHostedZone
。
-
以下代码示例演示了如何使用 list-health-checks。
- Amazon CLI
-
列出与当前 Amazon 账户关联的运行状况检查
以下
list-health-checks命令列出与当前 Amazon 账户关联的前 100 个运行状况检查的详细信息:aws route53 list-health-checks如果您有超过 100 个运行状况检查,或者想要将它们按小于 100 的组列出,请包含
--maxitems参数。例如,要一次列出一个运行状况检查,请使用以下命令:aws route53 list-health-checks --max-items1要查看下一个运行状况检查,请从上一个命令的响应中获取
NextToken的值,并将其包含在--starting-token参数中,例如:aws route53 list-health-checks --max-items1--starting-tokenZ3M3LMPEXAMPLE-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListHealthChecks
。
-
以下代码示例演示了如何使用 list-hosted-zones-by-name。
- Amazon 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-namewww.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" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListHostedZonesByName
。
-
以下代码示例演示了如何使用 list-hosted-zones。
- Amazon CLI
-
列出与当前 Amazon 账户关联的托管区
如下
list-hosted-zones命令列出与当前 Amazon 账户关联的前 100 个托管区的摘要信息:aws route53 list-hosted-zones如果您有超过 100 个托管区,或者想要将它们按小于 100 的数量分组列出,请包含
--max-items参数。例如,要一次列出一个托管区,请使用以下命令:aws route53 list-hosted-zones --max-items1要查看有关下一个托管区的信息,请从上一个命令的响应中获取
NextToken的值,并将其包含在--starting-token参数中,例如:aws route53 list-hosted-zones --max-items1--starting-tokenZ3M3LMPEXAMPLE-
有关 API 详细信息,请参阅 Amazon CLI 命令参考中的 ListHostedZones
。
-
以下代码示例演示了如何使用 list-query-logging-configs。
- Amazon CLI
-
列出查询日志记录配置
以下
list-query-logging-configs示例针对托管区Z1OX3WQEXAMPLE,列出了 Amazon 账户中前 100 个查询日志配置的相关信息。aws route53 list-query-logging-configs \ --hosted-zone-idZ1OX3WQEXAMPLE输出:
{ "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 查询。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListQueryLoggingConfigs
。
-
以下代码示例演示了如何使用 list-resource-record-sets。
- Amazon CLI
-
列出托管区中的资源记录集
以下
list-resource-record-sets命令列出了有关指定托管区中前 100 个资源记录集的摘要信息。aws route53 list-resource-record-sets --hosted-zone-idZ2LD58HEXAMPLE如果托管区中包含的资源记录集超过 100 个,或者想要将它们按小于 100 的数量分组列出,请包含
--maxitems参数。例如,要一次列出一个资源记录集,请使用以下命令:aws route53 list-resource-record-sets --hosted-zone-idZ2LD58HEXAMPLE--max-items1要查看有关托管区中下一个资源记录的信息,请从上一个命令的响应中获取
NextToken的值,并将其包含在--starting-token参数中,例如:aws route53 list-resource-record-sets --hosted-zone-idZ2LD58HEXAMPLE--max-items1--starting-tokenZ3M3LMPEXAMPLE要查看具有特定名称的所有资源记录集,请使用
--query参数将其过滤掉。例如:aws route53 list-resource-record-sets --hosted-zone-idZ2LD58HEXAMPLE--query"ResourceRecordSets[?Name == 'example.domain.']"-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListResourceRecordSets
。
-