A bucket is a container used to store objects in Object Storage Service (OSS). All objects in OSS are stored in buckets. This topic describes how to create a bucket.
Considerations
The sample code in this topic uses the region ID
cn-hangzhou
of the China (Hangzhou) region as an example and uses the public endpoint by default. If you want to access OSS from other Alibaba Cloud services in the same region, use the internal endpoint. For more information about the mapping between regions and endpoints of OSS, see OSS regions and endpoints.Starting from 10:00:00 on October 13, 2025 (UTC+8), OSS will gradually enable Block Public Access by default across all regions when creating buckets through API, SDK, or ossutil. For the effective implementation date in each region, see announcement. After this feature is enabled, you cannot create public access permissions, including public-read or public-read-write ACLs, or bucket policies with public access semantics. If your business requires public access, you can disable Block Public Access after the bucket is created.
Sample code
The following code provides an example on how to create a bucket named examplebucket:
# -*- coding: utf-8 -*-
import oss2
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the name of the bucket. Example: examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# Create a bucket.
# The following sample code provides an example on how to specify the storage class, ACL, and redundancy type when you create the bucket.
# In this example, the storage class is Standard, the ACL is private, and the redundancy type is zone-redundant storage (ZRS).
# bucketConfig = oss2.models.BucketCreateConfig(oss2.BUCKET_STORAGE_CLASS_STANDARD, oss2.BUCKET_DATA_REDUNDANCY_TYPE_ZRS)
# bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE, bucketConfig)
bucket.create_bucket()