All Products
Search
Document Center

Object Storage Service:mb

Last Updated:Apr 02, 2024

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.

  • This topic provides sample command lines that are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil command reference.

Create a bucket by specifying options in the command

Command syntax

./ossutil64 mb oss://bucketname 
[--acl <value>]
[--storage-class <value>]
[--redundancy-type <value>]

The following table describes the parameters and options in the 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 the objects in the bucket. Other users, including anonymous users, can perform only read operations on the objects in the bucket. This may result in unauthorized access to objects and high fees. If a user uploads prohibited data to the bucket, your legitimate interests and rights may be infringed. We recommend that you do not set this parameter to public-read unless necessary.

  • 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. Exercise caution when you set the ACL of a bucket to public-read-write.

--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 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 when you restore 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 when you restore Cold Archive objects.

For more information about storage classes, see Overview.

--redundancy-type

The redundancy type of the 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. We recommend that you exercise caution when you select this redundancy type.

Examples

  • You can run the following command to create a bucket named examplebucket:

    ./ossutil64 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 specified by the endpoint 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:

    ./ossutil64 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

./ossutil64 mb oss://bucketname local_xml_file

The following table describes the parameters in the 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

  1. 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>
  2. Read bucket configurations from the local file path by using ossutil and add the configurations to the bucket that you want to create:

    ./ossutil64 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 the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, you can add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command 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 that belongs to another Alibaba Cloud account:

./ossutil64 mb oss://examplebucket -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about common options, see Common options.