ListBuckets
Note
This operation is not supported for directory buckets.
Returns a list of all buckets owned by the authenticated sender of the request. To grant IAM permission to use
this operation, you must add the s3:ListAllMyBuckets
policy action.
For information about Amazon S3 buckets, see Creating, configuring, and working with Amazon S3 buckets.
Important
We strongly recommend using only paginated ListBuckets
requests. Unpaginated ListBuckets
requests are only supported for
Amazon Web Services accounts set to the default general purpose bucket quota of 10,000. If you have an approved
general purpose bucket quota above 10,000, you must send paginated ListBuckets
requests to list your account’s buckets.
All unpaginated ListBuckets
requests will be rejected for Amazon Web Services accounts with a general purpose bucket quota
greater than 10,000.
Request Syntax
GET /?bucket-region=BucketRegion
&continuation-token=ContinuationToken
&max-buckets=MaxBuckets
&prefix=Prefix
HTTP/1.1
Host: s3.amazonaws.com.cn
URI Request Parameters
The request uses the following URI parameters.
- bucket-region
-
Limits the response to buckets that are located in the specified Amazon Region. The Amazon Region must be expressed according to the Amazon Region code, such as
us-west-2
for the US West (Oregon) Region. For a list of the valid values for all of the Amazon Regions, see Regions and Endpoints.Note
Requests made to a Regional endpoint that is different from the
bucket-region
parameter are not supported. For example, if you want to limit the response to your buckets in Regionus-west-2
, the request must be made to an endpoint in Regionus-west-2
. - continuation-token
-
ContinuationToken
indicates to Amazon S3 that the list is being continued on this bucket with a token.ContinuationToken
is obfuscated and is not a real key. You can use thisContinuationToken
for pagination of the list results.Length Constraints: Minimum length of 0. Maximum length of 1024.
Required: No.
Note
If you specify the
bucket-region
,prefix
, orcontinuation-token
query parameters without usingmax-buckets
to set the maximum number of buckets returned in the response, Amazon S3 applies a default page size of 10,000 and provides a continuation token if there are more buckets. - max-buckets
-
Maximum number of buckets to be returned in response. When the number is more than the count of buckets that are owned by an Amazon account, return all the buckets in response.
Valid Range: Minimum value of 1. Maximum value of 10000.
- prefix
-
Limits the response to bucket names that begin with the specified bucket name prefix.
Request Body
The request does not have a request body.
Response Syntax
HTTP/1.1 200
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult>
<Buckets>
<Bucket>
<BucketRegion>string</BucketRegion>
<CreationDate>timestamp</CreationDate>
<Name>string</Name>
</Bucket>
</Buckets>
<Owner>
<DisplayName>string</DisplayName>
<ID>string</ID>
</Owner>
<ContinuationToken>string</ContinuationToken>
<Prefix>string</Prefix>
</ListAllMyBucketsResult>
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in XML format by the service.
- ListAllMyBucketsResult
-
Root level tag for the ListAllMyBucketsResult parameters.
Required: Yes
- Buckets
-
The list of buckets owned by the requester.
Type: Array of Bucket data types
- ContinuationToken
-
ContinuationToken
is included in the response when there are more buckets that can be listed with pagination. The nextListBuckets
request to Amazon S3 can be continued with thisContinuationToken
.ContinuationToken
is obfuscated and is not a real bucket.Type: String
- Owner
-
The owner of the buckets listed.
Type: Owner data type
- Prefix
-
If
Prefix
was sent with the request, it is included in the response.All bucket names in the response begin with the specified bucket name prefix.
Type: String
Examples
Example 1: Unpaginated ListBuckets request
This example lists all the buckets in your account in a single unpaginated response. Unpaginated requests are only supported for Amazon Web Services accounts that have the default service quota of 10,000 buckets. If you have an approved general purpose bucket quota that is greater than 10,000 buckets, all unpaginated requests will be rejected for your account.
GET / host:s3.us-east-2.amazonaws.com
HTTP/1.1 200 OK <ListAllMyBucketsResult> <Buckets> <Bucket> <CreationDate>2019-12-11T23:32:47+00:00</CreationDate> <Name>amzn-s3-demo-bucket</Name> </Bucket> <Bucket> <CreationDate>2019-11-10T23:32:13+00:00</CreationDate> <Name>amzn-s3-demo-bucket1</Name> </Bucket> </Buckets> <Owner> <DisplayName>Account+Name</DisplayName> <ID>AIDACKCEVSQ6C2EXAMPLE</ID> </Owner> </ListAllMyBucketsResult>
Example 2: Paginated ListBuckets request
The following example request lists all buckets in your account using pagination. It
gets the first page of results with the page size set to 1000 buckets. The response returns
a ContinuationToken
that is used in Example 3 to list the next 1000 buckets.
GET / max-buckets=1000 host:s3.us-east-2.amazonaws.com
HTTP/1.1 200 OK <ListAllMyBucketsResult> <Buckets> <Bucket> <CreationDate>2024-11-14T23:32:47+00:00</CreationDate> <Name>amzn-s3-demo-bucket</Name> <BucketRegion>us-east-1</BucketRegion> </Bucket> <Bucket> <CreationDate>2024-11-14T23:32:13+00:00</CreationDate> <Name>amzn-s3-demo-bucket1</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> </Buckets> <Owner> <DisplayName>Account+Name</DisplayName> <ID>AIDACKCEVSQ6C2EXAMPLE</ID> </Owner> <ContinuationToken>eyJNYXJrZXIiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxfQ==</ContinuationToken> </ListAllMyBucketsResult>
Example 3: Paginated ListBuckets request with continuation token
This example request uses the token returned in Example 2 to return the next 1000 buckets. Continue until there are no more results. If you do not receive a continuation token with your initial paginated ListBuckets request, then your single paginated request returned all of the buckets in your account.
GET / max-buckets=1000&continuation-token=eyJNYXJrZXIiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxfQ== host:s3.us-east-2.amazonaws.com
HTTP/1.1 200 OK <ListAllMyBucketsResult> <Buckets> <Bucket> <CreationDate>2024-11-14T23:32:47+00:00</CreationDate> <Name>amzn-s3-demo-bucket</Name> <BucketRegion>us-east-1</BucketRegion> </Bucket> <Bucket> <CreationDate>2024-11-14T23:32:13+00:00</CreationDate> <Name>amzn-s3-demo-bucket1</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> </Buckets> <Owner> <DisplayName>Account+Name</DisplayName> <ID>AIDACKCEVSQ6C2EXAMPLE</ID> </Owner> <ContinuationToken>eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiEXAMPLE=</ContinuationToken> </ListAllMyBucketsResult>
Example 4: Paginated ListBuckets request for buckets in US East (Ohio) (us-east-2)
The following example lists all the buckets in your account in the
us-east-2
Region. The first paginated response will return up to 1000 buckets. Requests made to a Regional
endpoint that is different from the bucket-region
parameter are not
supported.
GET / bucket-region=us-east-2&max-buckets=1000 host:s3.us-east-2.amazonaws.com
HTTP/1.1 200 OK <ListAllMyBucketsResult> <Buckets> <Bucket> <CreationDate>2024-11-14T23:32:47+00:00</CreationDate> <Name>DOC-EXAMPLE-BUCKET</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> <Bucket> <CreationDate>2024-11-14T23:32:13+00:00</CreationDate> <Name>DOC-EXAMPLE-BUCKET1002</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> </Buckets> <Owner> <DisplayName>Account+Name</DisplayName> <ID>AIDACKCEVSQ6C2EXAMPLE</ID> </Owner> <ContinuationToken>eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiEXAMPLEcd =</ContinuationToken> </ListAllMyBucketsResult>
Example 5: Paginated ListBuckets request for buckets in your account that begin with amzn-s3-demo-bucket in US East (Ohio) (us-east-2)
The following example lists all the buckets in your account located in the us-east-2
Region that begin with the amzn-s3-demo-bucket
bucket prefix. This
request uses pagination.
GET / bucket-region=us-east-2&max-buckets=1000&prefix=amzn-s3-demo-bucket host:s3.us-east-2.amazonaws.com
HTTP/1.1 200 OK <ListAllMyBucketsResult> <Buckets> <Bucket> <CreationDate>2024-11-14T23:32:47+00:00</CreationDate> <Name>amzn-s3-demo-bucket</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> <Bucket> <CreationDate>2024-11-14T23:32:13+00:00</CreationDate> <Name>DOC-EXAMPLE-BUCKET1002</Name> <BucketRegion>us-east-2</BucketRegion> </Bucket> </Buckets> <Owner> <DisplayName>Account+Name</DisplayName> <ID>AIDACKCEVSQ6C2EXAMPLE</ID> </Owner> <ContinuationToken>eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiEXAMPLE=</ContinuationToken> <amzn-s3-demo-bucket> </ListAllMyBucketsResult>
See Also
For more information about using this API in one of the language-specific Amazon SDKs, see the following: