本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Route 53 示例 Amazon CLI
以下代码示例向您展示了如何在 Route 53 中使用来执行操作和实现常见场景。 Amazon Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。
场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。
每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 change-resource-record-sets
。
- Amazon CLI
-
创建、更新或删除资源记录集
以下
change-resource-record-sets
命令使用文件中的hosted-zone-id
Z1R8UBAEXAMPLE
和 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
有关更多信息,请参阅《亚马逊 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" } }, {...} ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ChangeResourceRecordSets
中的。
-
以下代码示例演示如何使用 change-tags-for-resource
。
- Amazon 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
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ChangeTagsForResource
中的。
-
以下代码示例演示如何使用 create-health-check
。
- Amazon 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
命令。有关更多信息,请参阅《亚马逊 Route 53 开发者指南》中的 Amazon Route 53 健康检查和 DNS 故障转移。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateHealthCheck
中的。
-
以下代码示例演示如何使用 create-hosted-zone
。
- Amazon 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 的详细信息,请参阅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-id e75b48d9-547a-4c3d-88a5-ae4002397608
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteHealthCheck
中的。
-
以下代码示例演示如何使用 delete-hosted-zone
。
- Amazon CLI
-
删除托管区域
以下
delete-hosted-zone
命令删除带有以下值的id
托管区域Z36KTIQEXAMPLE
:aws route53 delete-hosted-zone --id Z36KTIQEXAMPLE
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteHostedZone
中的。
-
以下代码示例演示如何使用 get-change
。
- Amazon CLI
-
获取资源记录集更改的状态
以下
get-change
命令获取请求的状态和其他信息,该change-resource-record-sets
请求的状态和其它信息Id
为/change/CWPIK4URU2I5S
:aws route53 get-change --id /change/CWPIK4URU2I5S
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetChange
中的。
-
以下代码示例演示如何使用 get-health-check
。
- Amazon CLI
-
获取有关运行状况检查的信息
以下
get-health-check
命令获取有关具有以下值的运行状况检查的信息02ec8401-9879-4259-91fa-04e66d094674
:health-check-id
aws route53 get-health-check --health-check-id 02ec8401-9879-4259-91fa-04e66d094674
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetHealthCheck
中的。
-
以下代码示例演示如何使用 get-hosted-zone
。
- Amazon CLI
-
获取有关托管区域的信息
以下
get-hosted-zone
命令使用以下命令获取有关托管区域的信息Z1R8UBAEXAMPLE
:id
aws route53 get-hosted-zone --id Z1R8UBAEXAMPLE
-
有关 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-items 1
要查看下一次运行状况检查,请
NextToken
从对上一个命令的响应中取值并将其包含在--starting-token
参数中,例如:aws route53 list-health-checks --max-items 1 --starting-token Z3M3LMPEXAMPLE
-
有关 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-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" }
-
有关 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-items 1
要查看有关下一个托管区域的信息,请从上一个命令的响应中获取
NextToken
的值,并将其包含在--starting-token
参数中,例如:aws route53 list-hosted-zones --max-items 1 --starting-token Z3M3LMPEXAMPLE
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListHostedZones
中的。
-
以下代码示例演示如何使用 list-query-logging-configs
。
- Amazon CLI
-
列出查询日志配置
以下
list-query-logging-configs
示例列出了有关您 Amazon 账户中托管区域前 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 查询。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListQueryLoggingConfigs
中的。
-
以下代码示例演示如何使用 list-resource-record-sets
。
- Amazon 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.']"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListResourceRecordSets
中的。
-