

# Listing directory buckets
<a name="directory-buckets-objects-ListExamples"></a>

The following examples show how to list directory buckets by using the Amazon Web Services Management Console, Amazon SDKs, and Amazon CLI. 

## Using the S3 console
<a name="directory-bucket-list-console"></a>

1. Sign in to the Amazon Web Services Management Console and open the Amazon S3 console at [https://console.amazonaws.cn/s3/](https://console.amazonaws.cn/s3/).

1. In the navigation bar, choose the name of the currently displayed Amazon Web Services Region. Next, choose the Region in which you want to view a list of your directory buckets.

1. In the left navigation pane, choose **Directory buckets**. A list of directory buckets appears. To view the objects in the bucket, bucket properties, bucket permissions, metrics, access points associated with the bucket, or to manage the bucket, choose the bucket name.

## Using the Amazon SDKs
<a name="directory-bucket-list-sdks"></a>

------
#### [ SDK for Java 2.x ]

**Example**  
The following example lists directory buckets by using the Amazon SDK for Java 2.x.   

```
 public static void listBuckets(S3Client s3Client) {
        try {
            ListDirectoryBucketsRequest listDirectoryBucketsRequest = ListDirectoryBucketsRequest.builder().build();
            ListDirectoryBucketsResponse response = s3Client.listDirectoryBuckets(listDirectoryBucketsRequest);
            if (response.hasBuckets()) {
                for (Bucket bucket: response.buckets()) {
                    System.out.println(bucket.name());
                    System.out.println(bucket.creationDate());
                }
            }
        } 
        
        catch (S3Exception e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
    }
```

------
#### [ SDK for Python (Boto3) ]

**Example**  
The following example lists directory buckets by using the Amazon SDK for Python (Boto3).   

```
import logging
import boto3
from botocore.exceptions import ClientError
                                       
def list_directory_buckets(s3_client):
'''
Prints a list of all directory buckets in a Region
                                           
:param s3_client: boto3 S3 client                                         
:return: True if there are buckets in the Region, else False
'''
try:
    response = s3_client.list_directory_buckets()
    for bucket in response['Buckets']:
        print (bucket['Name'])
except ClientError as e:
    logging.error(e)
    return False
return True
                                          
                                          
if __name__ == '__main__': 
    region = '{{us-east-1}}'
    s3_client = boto3.client('s3', region_name = region)
    list_directory_buckets(s3_client)
```

------
#### [ Amazon SDK for .NET ]

**Example**  
The following example lists directory buckets by using the Amazon SDK for .NET.   

```
var listDirectoryBuckets = await amazonS3Client.ListDirectoryBucketsAsync(new ListDirectoryBucketsRequest
{
  MaxDirectoryBuckets = 10
  }).ConfigureAwait(false);
```

------
#### [ SDK for PHP ]

**Example**  
The following example lists directory buckets by using the Amazon SDK for PHP.   

```
require 'vendor/autoload.php';

$s3Client = new S3Client([
    'region'      => '{{us-east-1}}',
]);
$result = $s3Client->listDirectoryBuckets();
```

------
#### [ SDK for Ruby ]

**Example**  
The following example lists directory buckets by using the Amazon SDK for Ruby.   

```
s3 = Aws::S3::Client.new(region:'{{us-west-1}}')
s3.list_directory_buckets
```

------

## Using the Amazon CLI
<a name="list-directory-buckets-cli"></a>

The following `list-directory-buckets` example command shows how you can use the Amazon CLI to list your directory buckets in the {{us-east-1}} region. To run this command, replace the `{{user input placeholders}}` with your own information.

```
aws s3api list-directory-buckets --region {{us-east-1}} 
```

For more information, see [list-directory-buckets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/list-directory-buckets.html) in the *Amazon CLI Command Reference*.