Skip to content

list_buckets

list_buckets(
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    max_buckets: Optional[MaxBuckets] = None,
    continuation_token: Optional[Token] = None,
    prefix: Optional[Prefix] = None,
    bucket_region: Optional[BucketRegion] = None,
) -> ListBucketsOutput

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.

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.

You must URL encode any signed header values that contain spaces. For example, if your header value is my file.txt, containing two spaces after my, you must URL encode this value to my%20%20file.txt.

Parameters:

  • max_buckets (Optional[MaxBuckets], default: None ) –

    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 Web Services account, return all the buckets in response.

  • continuation_token (Optional[Token], default: None ) –

    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 this ContinuationToken for pagination of the list results.

    Length Constraints: Minimum length of 0. Maximum length of 1024.

    Required: No.

    If you specify the bucket-region, prefix, or continuation-token query parameters without using max-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.

  • prefix (Optional[Prefix], default: None ) –

    Limits the response to bucket names that begin with the specified bucket name prefix.

  • bucket_region (Optional[BucketRegion], default: None ) –

    Limits the response to buckets that are located in the specified Amazon Web Services Region. The Amazon Web Services Region must be expressed according to the Amazon Web Services 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 Web Services Regions, see Regions and Endpoints.

    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 Region us-west-2, the request must be made to an endpoint in Region us-west-2.

Raises:

Examples:

To list all buckets The following example returns all the buckets owned by the sender of this request.

>>> client.list_buckets()
Source code in docs_src/capo_s3/_services/s3.py
def list_buckets(
    self,
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    max_buckets: Optional["capo_s3.types.max_buckets.MaxBuckets"] = None,
    continuation_token: Optional["capo_s3.types.token.Token"] = None,
    prefix: Optional["capo_s3.types.prefix.Prefix"] = None,
    bucket_region: Optional["capo_s3.types.bucket_region.BucketRegion"] = None,
) -> "capo_s3.types.list_buckets_output.ListBucketsOutput":
    """<note> <p>This operation is not supported for directory buckets.</p> </note> <p>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 <code>s3:ListAllMyBuckets</code> policy action. </p> <p>For information about Amazon S3 buckets, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-buckets-s3.html">Creating, configuring, and working with Amazon S3 buckets</a>.</p> <important> <p>We strongly recommend using only paginated <code>ListBuckets</code> requests. Unpaginated <code>ListBuckets</code> 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 <code>ListBuckets</code> requests to list your account’s buckets. All unpaginated <code>ListBuckets</code> requests will be rejected for Amazon Web Services accounts with a general purpose bucket quota greater than 10,000. </p> </important> <important> <p>You must URL encode any signed header values that contain spaces. For example, if your header value is <code>my file.txt</code>, containing two spaces after <code>my</code>, you must URL encode this value to <code>my%20%20file.txt</code>.</p> </important>

    Args:
        max_buckets: <p>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 Web Services account, return all the buckets in response.</p>
        continuation_token: <p> <code>ContinuationToken</code> indicates to Amazon S3 that the list is being continued on this bucket with a token. <code>ContinuationToken</code> is obfuscated and is not a real key. You can use this <code>ContinuationToken</code> for pagination of the list results. </p> <p>Length Constraints: Minimum length of 0. Maximum length of 1024.</p> <p>Required: No.</p> <note> <p>If you specify the <code>bucket-region</code>, <code>prefix</code>, or <code>continuation-token</code> query parameters without using <code>max-buckets</code> 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.</p> </note>
        prefix: <p>Limits the response to bucket names that begin with the specified bucket name prefix.</p>
        bucket_region: <p>Limits the response to buckets that are located in the specified Amazon Web Services Region. The Amazon Web Services Region must be expressed according to the Amazon Web Services Region code, such as <code>us-west-2</code> for the US West (Oregon) Region. For a list of the valid values for all of the Amazon Web Services Regions, see <a href="https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region">Regions and Endpoints</a>.</p> <note> <p>Requests made to a Regional endpoint that is different from the <code>bucket-region</code> parameter are not supported. For example, if you want to limit the response to your buckets in Region <code>us-west-2</code>, the request must be made to an endpoint in Region <code>us-west-2</code>.</p> </note>

    Raises:
        capo_s3.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To list all buckets
        The following example returns all the buckets owned by the sender of this request.

        >>> client.list_buckets()
    """

    def _handler(
        req: "OperationRequest[capo_s3.types.list_buckets_request.ListBucketsRequest]",
    ) -> OperationResponse["capo_s3.types.list_buckets_output.ListBucketsOutput"]:
        import capo_s3._operations.amazon_s3.list_buckets

        output, http_response = (
            capo_s3._operations.amazon_s3.list_buckets.list_buckets(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListBuckets")
    )
    input_: capo_s3.types.list_buckets_request.ListBucketsRequest = {}
    if max_buckets is not None:
        input_["max_buckets"] = max_buckets
    if continuation_token is not None:
        input_["continuation_token"] = continuation_token
    if prefix is not None:
        input_["prefix"] = prefix
    if bucket_region is not None:
        input_["bucket_region"] = bucket_region

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output