

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

# `ListHostedZones`与 AWS SDK 或 CLI 配合使用
<a name="route-53_example_route-53_ListHostedZones_section"></a>

以下代码示例演示如何使用 `ListHostedZones`。

------
#### [ CLI ]

**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](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53/list-hosted-zones.html)*中的。

------
#### [ PowerShell ]

**适用于 PowerShell V4 的工具**  
**示例 1：输出所有公有和私有托管区。**  

```
Get-R53HostedZoneList
```
**示例 2：输出与 ID 为 NZ8 X2CISAMPLE 的可重复使用的委托集关联的所有托管区域**  

```
Get-R53HostedZoneList -DelegationSetId NZ8X2CISAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListHostedZones](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：输出所有公有和私有托管区。**  

```
Get-R53HostedZoneList
```
**示例 2：输出与 ID 为 NZ8 X2CISAMPLE 的可重复使用的委托集关联的所有托管区域**  

```
Get-R53HostedZoneList -DelegationSetId NZ8X2CISAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListHostedZones](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------
#### [ Rust ]

**适用于 Rust 的 SDK**  
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/route53#code-examples)中查找完整示例，了解如何进行设置和运行。

```
async fn show_host_info(client: &aws_sdk_route53::Client) -> Result<(), aws_sdk_route53::Error> {
    let hosted_zone_count = client.get_hosted_zone_count().send().await?;

    println!(
        "Number of hosted zones in region : {}",
        hosted_zone_count.hosted_zone_count(),
    );

    let hosted_zones = client.list_hosted_zones().send().await?;

    println!("Zones:");

    for hz in hosted_zones.hosted_zones() {
        let zone_name = hz.name();
        let zone_id = hz.id();

        println!("  ID :   {}", zone_id);
        println!("  Name : {}", zone_name);
        println!();
    }

    Ok(())
}
```
+  有关 API 的详细信息，请参阅适用[ListHostedZones](https://docs.rs/aws-sdk-route53/latest/aws_sdk_route53/client/struct.Client.html#method.list_hosted_zones)于 *Rust 的AWS SDK API 参考*。

------

有关 S AWS DK 开发者指南和代码示例的完整列表，请参阅[将 Route 53 与 S AWS DK 一起使用](sdk-general-information-section.md)。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。