A bucket is a container for objects stored in Object Storage Service (OSS). You must create a bucket before you upload an object to OSS. This topic describes how to create a bucket by using the mb command.
Usage notes
To create a bucket, you must have the oss:PutBucket permission. For more information, see Attach a custom policy to a RAM user.
For ossutil 1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you need to update the binary name based on the operating system. For more information, see ossutil command reference.
Create a bucket by specifying options in the command
Command syntax
ossutil mb oss://bucketname
[--acl <value>]
[--storage-class <value>]
[--redundancy-type <value>]
The following table describes the parameters and options in the command syntax.
Parameter/Option | Description |
bucketname | The name of the bucket that you want to create. A bucket name must be globally unique within OSS. The name of a bucket cannot be changed after the bucket is created. |
--acl | The access control list (ACL) of the bucket. Valid values: private (default): Only the bucket owner can perform read and write operations on the objects in the bucket. Other users cannot access the objects in the bucket. public-read: Only the bucket owner can perform write operations on objects in the bucket. All users, including anonymous users, can perform read operations on the objects in the bucket. This may result in unauthorized access to the data in your bucket and high fees. Please proceed with caution when you set the ACL of a bucket to public-read. public-read-write: All users, including anonymous users, can perform read and write operations on the objects in the bucket. This may result in unexpected access to the data in your bucket, and you may be charged unexpected fees. If a user uploads prohibited data or information, your legal rights may be infringed. We recommend that you do not set this parameter to public-read-write unless necessary.
|
--storage-class | The storage class of the bucket. Valid values: Standard (default): This storage class is suitable for data that is frequently accessed. IA: The Infrequent Access (IA) storage class is suitable for data that is infrequently accessed, such as data accessed once or twice a month. IA objects have a minimum storage period of 30 days and a minimum billable size of 64 KB. You can access IA objects in real time. You are charged for data retrieval fees when you access IA objects. Archive: This storage class is suitable for data that needs to be stored for a long period of time. Archive objects have a minimum storage period of 60 days and a minimum billable size of 64 KB. You must restore an Archive object before you can access the object. Approximately 1 minute is required to restore an Archive object. You are charged data retrieval fees for restoring Archive objects. ColdArchive: This storage class is suitable for long-term storage of data that is barely accessed. Cold Archive objects have a minimum storage period of 180 days and a minimum billable size of 64 KB. You must restore a Cold Archive object before you can access the object. The amount of time required to restore a Cold Archive object varies based on the object size and the restoration mode. You are charged data retrieval fees for restoring Cold Archive objects.
Note If you use OSS on CloudBox, only the Standard storage class is supported. For more information about storage classes, see Overview. |
--redundancy-type | Specifies the redundancy type of a bucket. Valid values: LRS (default): If you set the redundancy type of a bucket to locally redundant storage (LRS), OSS stores the copies of each object across different devices within the same zone. This way, OSS ensures data reliability and availability even if two storage devices are damaged at the same time. ZRS: If you set the redundancy type of a bucket to zone-redundant storage (ZRS), OSS stores multiple copies of your data across multiple zones in the same region. Your data is still accessible even if a zone becomes unavailable.
Important ZRS is supported in the following regions: China (Shenzhen), China (Beijing), China (Hangzhou), China (Shanghai), China (Hong Kong), Singapore, and Indonesia (Jakarta). ZRS increases your storage costs and cannot be disabled after it is enabled. Exercise caution when you select this redundancy type. If you use OSS on CloudBox, this parameter is not supported.
|
Examples
You can run the following command to create a bucket named examplebucket:
ossutil mb oss://examplebucket
If you do not specify the region in which you want to create the bucket, the bucket is created in the region that maps to the endpoint that is specified in the ossutil configuration file. For example, if the endpoint in the configuration file is https://oss-cn-hangzhou.aliyuncs.com
, the bucket is created in the China (Hangzhou) region.
You can run the following command to create a bucket named examplebucket and set the ACL of the bucket to private, storage class to IA, and redundancy type to ZRS:
ossutil mb oss://examplebucket --acl private --storage-class IA --redundancy-type ZRS
If the following sample output is displayed, the examplebucket bucket is created:
0.335189(s) elapsed
Create a bucket based on an XML file specified in the command
Command syntax
ossutil mb oss://bucketname local_xml_file
The following table describes the parameters in the command syntax.
Parameter | Description |
bucketname | The name of the bucket that you want to create. |
local_xml_file | The local file path that contains bucket configurations. Example: localfile.xml . |
Examples
Specify bucket configurations in the XML format in the localfile.xml
file.
<?xml version="1.0" encoding="UTF-8"?>
<CreateBucketConfiguration>
<StorageClass>IA</StorageClass>
<DataRedundancyType>LRS</DataRedundancyType>
</CreateBucketConfiguration>
Read bucket configurations from the local file path and add the configurations to the bucket that you want to create:
ossutil mb oss://examplebucket localfile.xml
Common options
If you use ossutil to switch to a bucket that is located in another region, add the -e option to specify the endpoint of the region in which the bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to specify the AccessKey ID of the specified account, and add the -k option to specify the AccessKey secret of the specified account.
For example, you can run the following command to create a bucket named examplebucket that is located in the China (Shanghai) region and belongs to another Alibaba Cloud account:
ossutil mb oss://examplebucket -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H****
For more information about common options, see Common options.