Creates a bucket.

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.
  • You can create up to 100 buckets in the same region by using an Alibaba Cloud account.
  • Each region can be accessed by using the endpoints of the region. For more information about regions and their endpoints, see Regions and endpoints.

Request syntax

PUT / HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
x-oss-acl: Permission
Authorization: SignatureValue
<?xml version="1.0" encoding="UTF-8"?>
<CreateBucketConfiguration>
    <StorageClass>Standard</StorageClass>
</CreateBucketConfiguration>

Request headers

HeaderTypeRequiredExampleDescription
x-oss-aclStringNoprivateThe access control list (ACL) of the bucket that you want to create. Default value: private. Valid values:
  • public-read-write
  • public-read
  • private

For more information, see Bucket ACL.

x-oss-resource-group-idStringNorg-aek27tc****The ID of the resource group.
  • If you include the header in the request and specify the ID of the resource group, the created bucket belongs to the resource group.

    If the ID of the resource group is set to rg-default-id, the created bucket belongs to the default resource group.

  • If you do not include the header in the request, the created bucket belongs to the default resource group.

To obtain the ID of a resource group, you can use the Resource Management console or call the ListResourceGroups operation. For more information, see View basic information of a resource group and ListResourceGroups.

x-oss-hns-statusStringNodisabledSpecifies whether to enable the hierarchical namespace feature for the bucket.

You can enable or disable the hierarchical namespace feature for a bucket only when you create the bucket. The hierarchical namespace feature cannot be enabled or disabled for existing buckets. Default value: disabled. Valid values:

  • enabled: The hierarchical namespace feature is enabled for the bucket.

    After the hierarchical namespace feature is enabled for the bucket, you can create, delete, and rename directories.

  • disabled: The hierarchical namespace feature is disabled for the bucket.

The request headers involved in the PutBucket operation also contain common request headers. For more information, see Common request headers.

Request parameters

ParameterTypeRequiredExampleDescription
StorageClassStringNoStandardThe storage class of the bucket. Default value: Standard. Valid values:
  • Standard
  • IA
  • Archive
  • ColdArchive

Parent nodes: CreateBucketConfiguration

Child nodes: none

DataRedundancyTypeStringNoLRSThe redundancy type of the bucket. Default value: LRS. Valid values:
  • LRS

    Locally redundant storage (LRS) stores the copies of each object across different devices in the same zone. This way, Object Storage Service (OSS) ensures data reliability and availability even if two storage devices are damaged at the same time.

  • ZRS

    Standard ZRS uses the multi-zone mechanism to distribute user data across three zones in the same region. If one zone becomes unavailable, you can continue to access the data that is stored in the other two zones.

Parent nodes: CreateBucketConfiguration

Child nodes: none

Response headers

The response to a PutBucket request contains only common response headers. For more information, see Common response headers.

Examples

  • Create a bucket in the default resource group
    PUT / HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Fri, 24 Feb 2017 03:15:40 GMT
    x-oss-acl: private
    Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:77Dvh5wQgIjWjwO/KyRt8dOP****
    <?xml version="1.0" encoding="UTF-8"?>
    <CreateBucketConfiguration>
        <StorageClass>Standard</StorageClass>
        <DataRedundancyType>LRS</DataRedundancyType>    
    </CreateBucketConfiguration>
  • Sample success response
    HTTP/1.1 200 OK
    x-oss-request-id: 534B371674E88A4D8906****
    Date: Fri, 24 Feb 2017 03:15:40 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS
  • Create a bucket in a specified resource group
    Sample request
    PUT / HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Fri, 24 Feb 2017 03:15:40 GMT
    x-oss-acl: private
    x-oss-resource-group-id: rg-aek27tc********
    Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:77Dvh5wQgIjWjwO/KyRt8dOP****
    <?xml version="1.0" encoding="UTF-8"?>
    <CreateBucketConfiguration>
        <StorageClass>Standard</StorageClass>
    </CreateBucketConfiguration>
    Sample success response
    HTTP/1.1 200 OK
    x-oss-request-id: 534B371674E88A4D8906****
    Date: Fri, 24 Feb 2017 03:15:40 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS

OSS SDKs

You can use OSS SDKs for the following programming languages to call the PutBucket operation:

Error codes

Error codeHTTP status codeDescription
InvalidBucketName400The error message returned because the bucket name does not conform to the naming conventions.
AccessDenied403Possible causes:
  • The information for user authentication is not imported when you initiate the PutBucket request.
  • You do not have the permissions to perform the PutBucket operation.
TooManyBuckets400The error message returned because the maximum number of buckets has been reached. You can use an Alibaba Cloud account to create up to 100 buckets in the same region.
BucketAlreadyExists409Possible causes:
  • The specified bucket already exists or is owned by another user. Create a new bucket and specify a bucket name that conforms to the naming conventions.
  • The status of the hierarchical namespace feature cannot be modified for the existing bucket. You can enable or disable the hierarchical namespace feature for a bucket only when you create the bucket.