All Products
Search
Document Center

Object Storage Service:Create a bucket

Last Updated:Aug 08, 2025

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.

Usage notes

  • The examples in this topic use the China (Hangzhou) region, which has the region ID cn-hangzhou. The sample code uses the public endpoint by default. To access OSS from other Alibaba Cloud products in the same region, you can use the internal endpoint. For more information about the mappings between OSS regions and endpoints, see Regions and endpoints.

  • From 10:00 (UTC+8) on October 13, 2025, OSS will implement a phased adjustment across all regions to enable Block Public Access by default for new buckets created using the API, OSS SDKs, or ossutil. For details about the exact times when the adjustment will take effect in each region, see [Official Announcement] Adjustment to Public Access Blocking Configurations for Newly Created Buckets. Once Block Public Access is enabled, you cannot configure public access permissions, including public ACLs (public read and public read/write) and bucket policies that allows public access. You can disable this feature after the bucket is created if your business requires public access.

Examples

The following code provides an example of how to create a bucket named examplebucket.

# -*- coding: utf-8 -*-
import oss2

# An Alibaba Cloud account AccessKey has permissions for all API operations, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API access or routine O&M. To create a RAM user, log on to the RAM console.
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Set yourEndpoint to the endpoint of the region where the bucket is located. For example, for the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the bucket name. For example, examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# Create the bucket.
# To set the storage class, access permissions, and data disaster recovery type when you create the bucket, see the following code.
# The following code provides an example of how to set the storage class to Standard, the access permissions to private, and the data disaster recovery type to zone-redundant storage.
# 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()

References

  • For the complete sample code to create a bucket, see the GitHub example.

  • For more information about the API operation to create a bucket, see PutBucket.