A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to create a bucket.

The following code provides an example on how to create a bucket:

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

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS, because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create your RAM user, log on to https://ram.console.aliyun.com.
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# After you specify the endpoint and bucket name, you can create a bucket in the specified region. This example uses the endpoint of the China (Hangzhou) region. Specify the actual endpoint based on your requirements.
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

# Create a bucket.
# The following code provides an example on how to specify the storage class, ACL, and the type of disaster recovery when you create a bucket.
# In this example, the storage class is Standard, the ACL is private, and the type of disaster recovery is 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()

For more information about the bucket naming conventions, see Bucket.

You can specify the ACL and storage class when you create a bucket. For more information, see Set the ACL for a bucket and Overview of storage classes.

The following code provides an example on how to create a bucket of the Infrequent Access (IA) storage class:

# Set the storage class of the bucket to IA and the ACL to public read.
bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ, oss2.models.BucketCreateConfig(oss2.BUCKET_STORAGE_CLASS_IA))            

For more information about how to create a bucket, see PutBucket.