View a markdown version of this page

Use ListHostedZones with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListHostedZones with an AWS SDK or CLI

The following code examples show how to use ListHostedZones.

CLI
AWS CLI

To list the hosted zones associated with the current AWS account

The following list-hosted-zones example lists summary information about the first 100 hosted zones that are associated with the current AWS account.

aws route53 list-hosted-zones

Output:

{ "HostedZones": [ { "Id": "/hostedzone/Z1R8UBAEXAMPLE", "Name": "example.com.", "CallerReference": "2014-04-01-18:47", "Config": { "Comment": "command-line version", "PrivateZone": false }, "ResourceRecordSetCount": 2 } ] }

If you have more than 100 hosted zones, or if you want to list them in groups smaller than 100, include the --max-items parameter. For example, to list hosted zones one at a time, use the following command.

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

To view information about the next hosted zone, take the value of NextToken from the response to the previous command, and include it in the --starting-token parameter, as shown in the following example.

aws route53 list-hosted-zones \ --max-items 1 \ --starting-token Z3M3LMPEXAMPLE

For more information, see Listing public hosted zones in the Amazon Route 53 Developer Guide.

PowerShell
Tools for PowerShell V4

Example 1: Outputs all of your public and private hosted zones.

Get-R53HostedZoneList

Example 2: Outputs all of the hosted zones that are associated with the reusable delegation set that has the ID NZ8X2CISAMPLE

Get-R53HostedZoneList -DelegationSetId NZ8X2CISAMPLE
  • For API details, see ListHostedZones in AWS Tools for PowerShell Cmdlet Reference (V4).

Tools for PowerShell V5

Example 1: Outputs all of your public and private hosted zones.

Get-R53HostedZoneList

Example 2: Outputs all of the hosted zones that are associated with the reusable delegation set that has the ID NZ8X2CISAMPLE

Get-R53HostedZoneList -DelegationSetId NZ8X2CISAMPLE
  • For API details, see ListHostedZones in AWS Tools for PowerShell Cmdlet Reference (V5).

Rust
SDK for Rust
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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(()) }