Use get_bucket_info() to retrieve metadata about a bucket — including its region, storage class, creation date, endpoints, owner, access control list (ACL), data redundancy type, and access tracking status.
Prerequisites
Before you begin, ensure that you have:
The
oss:GetBucketInfopermission on the target bucket. For details, see Attach a custom policy to a RAM user.Access credentials configured as environment variables. For details, see Configure access credentials.
Get bucket information
The following example retrieves bucket information using the China (Hangzhou) public endpoint. To use an internal endpoint instead, see Regions and endpoints.
To create an OSSClient instance using a custom domain name or Security Token Service (STS), see Initialization.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Load access credentials from environment variables.
# Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this example.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Set the endpoint for the region where your bucket is located.
# Example: https://oss-cn-hangzhou.aliyuncs.com for China (Hangzhou).
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Set the region ID. Required for V4 signatures.
region = "cn-hangzhou"
# Replace yourBucketName with the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)
# Retrieve bucket information.
bucket_info = bucket.get_bucket_info()
# Print individual fields from the response.
print("name: " + bucket_info.name)
print("storage class: " + bucket_info.storage_class)
print("creation date: " + bucket_info.creation_date)
print("intranet_endpoint: " + bucket_info.intranet_endpoint)
print("extranet_endpoint " + bucket_info.extranet_endpoint)
print("owner: " + bucket_info.owner.id)
print("grant: " + bucket_info.acl.grant)
print("data_redundancy_type:" + bucket_info.data_redundancy_type)
# access_monitor requires Python SDK 2.16.1 or later.
print("access_monitor:" + bucket_info.access_monitor)Response fields
get_bucket_info() returns a GetBucketInfoResult object. The following fields are available:
| Field | Type | Description |
|---|---|---|
name | string | Bucket name |
storage_class | string | Storage class of the bucket (for example, Standard, IA, Archive) |
creation_date | string | Date the bucket was created |
intranet_endpoint | string | Internal endpoint for accessing the bucket from other Alibaba Cloud services in the same region |
extranet_endpoint | string | Public endpoint for accessing the bucket over the internet |
owner.id | string | Alibaba Cloud account ID of the bucket owner |
acl.grant | string | ACL of the bucket (for example, private, public-read, public-read-write) |
data_redundancy_type | string | Data redundancy type of the bucket (for example, LRS, ZRS) |
access_monitor | string | Access tracking status. Requires Python SDK 2.16.1 or later. |
References
For the complete sample code, see GitHub.
For the underlying API, see GetBucketInfo.