All Products
Search
Document Center

Object Storage Service:Create a bucket

Last Updated:Dec 08, 2025

A bucket is the basic container in Object Storage Service (OSS) that holds your files. It has unlimited capacity and scales elastically.

Basic configurations

These are the core settings for a bucket. They cannot be changed after the bucket is created.

  • Bucket name: The bucket name must be globally unique. We recommend that you name the bucket based on your department or service for easy identification and management. For example: hr-documents.

  • Region: The region determines the physical location of your data. Choose a region based on the following priorities:

    1. Compliance: Choose a region that meets your regulatory requirements.

    2. Performance: To reduce network latency, choose the region closest to your target users. If you access data from another Alibaba Cloud product, such as an ECS instance, choose the same region. This lets you use the internal network for free and reduces cross-region latency.

    3. Feature support: Confirm that the region supports the features you need. For more information, see the Release notes.

    4. Cost: After you meet the preceding conditions, choose a region with lower pricing.

If you specify only the bucket name and region, the following default settings are used: Standard storage, zone-redundant storage, private access, and Block Public Access enabled.

Console

  1. On the Bucket page of the OSS console, click Create Bucket.

  2. In the Create Bucket panel, set the Bucket Name and Region, and then click Create.

ossutil

You can use the ossutil command line interface (CLI) to create a bucket. For more information about how to install ossutil, see Install ossutil.

  1. Configure the bucket region.

    ossutil config
  2. Press Enter to skip the initial configuration items until the region configuration prompt appears:

    Please enter Region [cn-hangzhou]:

    Enter the ID of the destination region, such as cn-beijing, and press Enter. Alternatively, press Enter to use the default region cn-hangzhou. You can find region IDs in the OSS region list.

  3. Create a bucket named examplebucket.

    ossutil mb oss://examplebucket
  4. Verify that the bucket was created.

    ossutil ls

For more information about this command, see mb (create a bucket).

SDK

The following code samples show how to create a bucket using common SDKs. For code samples for other SDKs, see SDK introduction.

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {

    public static void main(String[] args) throws Exception {
        // Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
        String endpoint = "yourEndpoint";
        // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of the bucket. 
        String bucketName = "examplebucket";
        // Specify the ID of the resource group. If you do not specify a resource group ID, the bucket belongs to the default resource group. 
        //String rsId = "rg-aek27tc****";
        // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
        String region = "cn-hangzhou";
        
        // Create an OSSClient instance. 
        // Call the shutdown method to release associated resources when the OSSClient is no longer in use.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);        
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)               
        .build();

        try {
            // Create a bucket and enable the hierarchical namespace feature for the bucket. 
            CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName).withHnsStatus(HnsStatus.Enabled);
            // The following code provides an example on how to specify the storage class, access control list (ACL), and redundancy type when you create the bucket. 
            // In this example, the storage class of the bucket is Standard. 
            createBucketRequest.setStorageClass(StorageClass.Standard);
            // The default redundancy type of the bucket is DataRedundancyType.LRS. 
            createBucketRequest.setDataRedundancyType(DataRedundancyType.LRS);
            // Set the ACL of the bucket to public-read. The default ACL is private. 
            createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
            // When you create a bucket in a region that supports resource groups, you can configure a resource group for the bucket. 
            //createBucketRequest.setResourceGroupId(rsId);

            ossClient.createBucket(createBucketRequest);

            // Create a bucket. 
            ossClient.createBucket(createBucketRequest);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}
import argparse
import alibabacloud_oss_v2 as oss

# Create a command line argument parser.
parser = argparse.ArgumentParser(description="put bucket sample")
# Specify the required command line parameter --region, which specifies the region in which the bucket is located.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Specify the required command line parameter --bucket, which specifies the name of the bucket. 
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
# Specify the optional command line parameter --endpoint, which specifies the endpoint that other services can use to access OSS.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')

def main():
    args = parser.parse_args()  # Parse command line parameters.

    # Load access credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default configurations of the SDK and specify the credential provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    # Specify the region in which the bucket is located.
    cfg.region = args.region
    # If the endpoint parameter is provided, specify the endpoint that other services can use to access OSS.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Use the configurations to create an OSSClient instance.
    client = oss.Client(cfg)

    # Execute the request to create a bucket and set its storage class to Standard.
    result = client.put_bucket(oss.PutBucketRequest(
        bucket=args.bucket,
        create_bucket_configuration=oss.CreateBucketConfiguration(
            storage_class='Standard'
        )
    ))
    # Output the HTTP status code in the response and the request ID used to check whether the request is successful.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
    )


if __name__ == "__main__":
    main()  # Entry point of the script. The main function is invoked when the file is run directly.
package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

// Specify the global variables.
var (
	region     string // The region.
	bucketName string // The name of the bucket.
)

// Specify the init function used to initialize command line parameters.
func init() {
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}

func main() {
	// Parse command line parameters.
	flag.Parse()

	// Check whether the bucket name is empty.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	// Check whether the region is empty.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	// Load the default configurations and specify the credential provider and region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	// Create an OSS client.
	client := oss.NewClient(cfg)

	request := &oss.PutBucketRequest{
		Bucket: oss.Ptr(bucketName), // The name of the bucket.
	}

	// Send a request to create a bucket.
	result, err := client.PutBucket(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put bucket %v", err)
	}

	// Display the result of the bucket creation.
	log.Printf("put bucket result:%#v\n", result)
}
<?php

// Automaticically load objects and dependency libraries.
require_once __DIR__ . '/../vendor/autoload.php'; 

use AlibabaCloud\Oss\V2 as Oss;

// Specify command line parameters.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region parameter is required. Example: oss-cn-hangzhou.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint parameter is optional.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // The name of the bucket is required.
];

// Generate a list of long options for parsing command line parameters.
$longopts = \array_map(function ($key) {
    return "$key:"; // The colon (:) following each parameter indicates that the parameter is required.
}, array_keys($optsdesc));

// Parse command line parameters.
$options = getopt("", $longopts); 

// Check whether the required parameters have been configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Specifies that the required parameters are not configured.
        exit(1); 
    }
}

// Retrieve the values of the command line parameters.
$region = $options["region"]; // Region in which the bucket is located.
$bucket = $options["bucket"]; // Name of the bucket.

// Load the credential information (AccessKeyId and AccessKeySecret) from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); 

// Use the default configuration of the SDK.
$cfg = Oss\Config::loadDefault(); 
$cfg->setCredentialsProvider($credentialsProvider); // Specify the credential provider.
$cfg->setRegion($region); // Specify the region.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]); // Specify the endpoint if one is provided.
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg); 

// Create a request to initiate bucket creation.
$request = new Oss\Models\PutBucketRequest($bucket); 

// Call the putBucket method.
$result = $client->putBucket($request);

// Output the result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // HTTP status code.
    'request id:' . $result->requestId // Unique ID of the request.
);
using Aliyun.OSS;
using Aliyun.OSS.Common;

// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
var endpoint = "yourEndpoint";
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
var accessKeyId = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_ID");
var accessKeySecret = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET");
// Specify the name of the bucket. 
var bucketName = "examplebucket";
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";

// Create a ClientConfiguration instance and modify the default parameters based on your requirements.
var conf = new ClientConfiguration();

// Use the signature algorithm V4.
conf.SignatureVersion = SignatureVersion.V4;

// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
client.SetRegion(region);
// Create a bucket. 
try
    {
        var request = new CreateBucketRequest(bucketName);
        // Set the access control list (ACL) of the bucket to PublicRead. The default value is private. 
        request.ACL = CannedAccessControlList.PublicRead;
        // Set the redundancy type of the bucket to zone-redundant storage (ZRS). 
        request.DataRedundancyType = DataRedundancyType.ZRS;
        client.CreateBucket(request);
        Console.WriteLine("Create bucket succeeded");
    }
    catch (Exception ex)
    {
        Console.WriteLine("Create bucket failed. {0}", ex.Message);
    }
const OSS = require('ali-oss');

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket.
  bucket: 'yourBucketName',
});

// Create the bucket. 
async function putBucket() {
  try {
    const options = {
      storageClass: 'Standard', // By default, the storage class of a bucket is Standard. To set the storage class of the bucket to Archive, set storageClass to Archive. 
      acl: 'private', // By default, the access control list (ACL) of a bucket is private. To set the ACL of the bucket to public read, set acl to public-read. 
      dataRedundancyType: 'LRS' // By default, the redundancy type of a bucket is locally redundant storage (LRS). To set the redundancy type of the bucket to zone-redundant storage (ZRS), set dataRedundancyType to ZRS. 
    }
    // Specify the name of the bucket. 
    const result = await client.putBucket('examplebucket', options);
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

putBucket();        
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the name of the bucket. Example: examplebucket. 
client.create_bucket('examplebucket')
// Construct a request to create a bucket. 
// Specify the name of the bucket. 
CreateBucketRequest createBucketRequest=new CreateBucketRequest("examplebucket");. 
// Specify the access control list (ACL) of the bucket. 
// createBucketRequest.setBucketACL(CannedAccessControlList.Private);
// Specify the storage class of the bucket. 
// createBucketRequest.setBucketStorageClass(StorageClass.Standard);

// Create the bucket asynchronously. 
OSSAsyncTask createTask = oss.asyncCreateBucket(createBucketRequest, new OSSCompletedCallback<CreateBucketRequest, CreateBucketResult>() {
    @Override
    public void onSuccess(CreateBucketRequest request, CreateBucketResult result) {
        Log.d("asyncCreateBucket", "Success");
    }
    @Override
    public void onFailure(CreateBucketRequest request, ClientException clientException, ServiceException serviceException) {
        // Handle request exceptions. 
        if (clientException != null) {
            // Handle client exceptions, such as network exceptions. 
            clientException.printStackTrace();
        }
        if (serviceException != null) {
            // Handle service exceptions. 
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /* Initialize information about the account that is used to access OSS. */
    
    /* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
    std::string Endpoint = "yourEndpoint";
    
    /* Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. */
    std::string Region = "yourRegion";
    
    /* Specify the name of the bucket. Example: examplebucket. */
    std::string BucketName = "examplebucket";

    /* Initialize resources, such as network resources. */
    InitializeSdk();

    ClientConfiguration conf;
    conf.signatureVersion = SignatureVersionType::V4;
    /* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */
    auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
    OssClient client(Endpoint, credentialsProvider, conf);
    client.SetRegion(Region);

    /* Specify the name, storage class, and access control list (ACL) of the bucket. */
    CreateBucketRequest request(BucketName, StorageClass::IA, CannedAccessControlList::PublicReadWrite);
    /* Set the redundancy type of the bucket to zone-redundant storage (ZRS). */
    //request.setDataRedundancyType(DataRedundancyType::ZRS);

    /* Create the bucket. */
    auto outcome = client.CreateBucket(request);

    if (!outcome.isSuccess()) {
        /* Handle exceptions. */
        std::cout << "CreateBucket fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        return -1;
    }

    /* Release resources, such as network resources. */
    ShutdownSdk();
    return 0;
}
// Construct a request to create a bucket. 
OSSCreateBucketRequest * create = [OSSCreateBucketRequest new];
// Set the bucket name to examplebucket. 
create.bucketName = @"examplebucket";
// Set the access control list (ACL) of the bucket to private. 
create.xOssACL = @"private";
// Set the storage class of the bucket to Infrequent Access (IA). 
create.storageClass = OSSBucketStorageClassIA;

OSSTask * createTask = [client createBucket:create];

[createTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"create bucket success!");
    } else {
        NSLog(@"create bucket failed, error: %@", task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [createTask waitUntilFinished];          
#include "oss_api.h"
#include "aos_http_io.h"
/* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* Specify the name of the bucket. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. */
const char *region = "yourRegion";

void init_options(oss_request_options_t *options)
{
    options->config = oss_config_create(options->pool);
    /* Use a char* string to initialize data of the aos_string_t type. */
    aos_str_set(&options->config->endpoint, endpoint);
    /* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */  
    aos_str_set(&options->config->access_key_id, getenv("OSS_ACCESS_KEY_ID"));
    aos_str_set(&options->config->access_key_secret, getenv("OSS_ACCESS_KEY_SECRET"));
    // Specify two additional parameters.
    aos_str_set(&options->config->region, region);
    options->config->signature_version = 4;
    /* Specify whether to use CNAME to access OSS. The value of 0 indicates that CNAME is not used.  */
    options->config->is_cname = 0;
    /* Configure network parameters, such as the timeout period. */
    options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
    /* Call the aos_http_io_initialize method in main() to initialize global resources, such as network resources and memory resources.  */
    if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
        exit(1);
    }
    /* Create a memory pool to manage memory. aos_pool_t is equivalent to apr_pool_t. The code used to create a memory pool is included in the APR library. */
    aos_pool_t *pool;
    /* Create a memory pool. The value of the second parameter is NULL. This value specifies that the pool does not inherit other memory pools. */
    aos_pool_create(&pool, NULL);
    /* Create and initialize options. This parameter includes global configuration information, such as endpoint, access_key_id, access_key_secret, is_cname, and curl. */
    oss_request_options_t *oss_client_options;
    /* Allocate the memory resources in the memory pool to the options. */
    oss_client_options = oss_request_options_create(pool);
    /* Initialize oss_client_options. */
    init_options(oss_client_options);
    /* Initialize the parameters. */
    aos_string_t bucket;
    oss_acl_e oss_acl = OSS_ACL_PRIVATE;
    aos_table_t *resp_headers = NULL; 
    aos_status_t *resp_status = NULL; 
    /* Assign char* data to a bucket of the aos_string_t type.  */
    aos_str_set(&bucket, bucket_name);
    /* Create the bucket. */
    resp_status = oss_create_bucket(oss_client_options, &bucket, oss_acl, &resp_headers);
    /* Determine whether the bucket is created.  */
    if (aos_status_is_ok(resp_status)) {
        printf("create bucket succeeded\n");
    } else {
        printf("create bucket failed\n");
    }
    /* Release the memory pool. This operation releases the memory resources allocated for the request. */
    aos_pool_destroy(pool);
    /* Release the allocated global resources.  */
    aos_http_io_deinitialize();
    return 0;
}

API

When you call the PutBucket operation, you can specify the name and region in the Host request header.

Storage class

OSS provides five storage classes: Standard, Infrequent Access (IA), Archive, Cold Archive, and Deep Cold Archive. The default storage class is Standard. These classes have decreasing costs and increasing access restrictions to suit data with different access frequencies.

Objects inherit the storage class of the bucket by default. Although you cannot change the storage class of a bucket after it is created, you can use lifecycle rules to automatically transition the storage class of objects to optimize costs.

  • Standard

    Suitable for active data where a single file is accessed more than once a month. It supports real-time access. This is the preferred choice if you are unsure about data access frequency. You can later use lifecycle rules to automatically transition objects to a lower-cost storage class.

  • Infrequent Access (IA):

    Suitable for warm data where a single file is accessed once a month or less, such as backup files and operation logs. It supports real-time access but has a minimum storage duration of 30 days. If you delete an object before 30 days have passed, you are still charged for 30 days of storage. This storage class is not suitable for temporary or test data.

  • Archive:

    Suitable for cold data where a single file is accessed less than once every 90 days. It supports real-time access of Archive objects. You can also choose to restore the object first and then read it. Restoration takes about 1 minute. It has a minimum storage duration of 60 days.

    Restore: To change the state of data back to accessible. This process requires a waiting period.
  • Cold Archive

    Suitable for data where a single file is accessed less than once a year. You must restore the data before you can read it. Restoration takes 1 to 12 hours. This class has lower costs and a minimum storage duration of 180 days.

  • Deep Cold Archive

    This is the lowest-cost option and is suitable for data where a single file is accessed less than once a year. Restoration takes 12 or 48 hours. It has a minimum storage duration of 180 days. Creating a bucket with this storage class is not recommended. We recommend that you use lifecycle rules to automatically transition data to this class.

Console

When you create a bucket, you can configure the bucket storage class based on your needs.

ossutil

The following command creates a bucket named examplebucket with the Infrequent Access (IA) storage class.

ossutil mb oss://examplebucket --storage-class IA

For more information about this command, see mb (create a bucket).

OSS SDK

The following code samples show how to create a bucket using common SDKs. For code samples for other SDKs, see SDK introduction.

Java

To set the storage class, you can configure the CreateBucketRequest object as follows.

// Prepare a request object that contains the storage class.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("your-bucket-name");
createBucketRequest.setStorageClass(StorageClass.IA); // Specify the storage class here.

// Options: StorageClass.Standard, StorageClass.IA, StorageClass.Archive, etc.

For a complete example, see Create a bucket using OSS SDK for Java.

Python

When you call the client.put_bucket method, you can specify the storage class using the create_bucket_configuration parameter.

# Prepare a request object that contains the storage class.
req = oss.PutBucketRequest(
    bucket="your-bucket-name",
    create_bucket_configuration=oss.CreateBucketConfiguration(
        storage_class='IA'  # Specify the storage class here.
    )
)

# Options: 'Standard', 'IA', 'Archive', 'ColdArchive', 'DeepColdArchive'

For a complete example, see Create a bucket (Python SDK V2).

Go

To set the storage class, you can configure the CreateBucketConfiguration field when you create a PutBucketRequest.

request := &oss.PutBucketRequest{
    Bucket: oss.Ptr("your-bucket-name"),
    CreateBucketConfiguration: &oss.CreateBucketConfiguration{
        StorageClass: oss.StorageClassIA, // Specify the storage class here.
    },
}

// Options: oss.StorageClassStandard, oss.StorageClassIA, oss.StorageClassArchive, etc.

For a complete example, see Create a bucket (Go SDK V2).

PHP

To set the storage class, you can pass a CreateBucketConfiguration object to the constructor when you create a PutBucketRequest object.

// Prepare a request object that contains configurations such as the storage class.
$request = new Oss\Models\PutBucketRequest(
    "your-bucket-name",
    null, // acl
    null, // resourceGroupId
    new Oss\Models\CreateBucketConfiguration(
        'IA',             // Specify the storage class here.
    )
);

/* 
 * Optional storage classes: 'Standard', 'IA', 'Archive', 'ColdArchive', 'DeepColdArchive'
*/

For a complete example, see Create a bucket (PHP SDK V2).

C#

To set the storage class, you can create a CreateBucketRequest object and configure its properties as follows.

// Prepare a request object that contains the storage class configuration.
var request = new CreateBucketRequest("your-bucket-name");
request.StorageClass = StorageClass.IA;             // Specify the storage class here.

// Optional storage classes: StorageClass.Standard, StorageClass.IA, StorageClass.Archive, etc.

For a complete example, see Create buckets.

Node.js

To set the storage class, you can create an options object and pass it to the putBucket method.

// Prepare an options object that contains the storage class configuration.
const options = {
  storageClass: 'IA',              // Specify the storage class here.
};

// Optional storage classes: 'Standard', 'IA', 'Archive', 'ColdArchive', 'DeepColdArchive'

For a complete example, see Create a bucket.

Android

To set the storage class or access permissions, you can create and configure a CreateBucketRequest object as follows.

// Prepare a request object that contains configurations such as the storage class.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("your-bucket-name");
createBucketRequest.setBucketStorageClass(StorageClass.IA);         // Specify the storage class here.

// Optional storage classes: StorageClass.Standard, StorageClass.IA, StorageClass.Archive, etc.

For a complete example, see Create a bucket (Android SDK).

iOS

To set the storage class, create an OSSCreateBucketRequest object and configure the following properties.

// Prepare a request object that contains configurations such as the storage class.
OSSCreateBucketRequest *create = [OSSCreateBucketRequest new];
create.bucketName = @"your-bucket-name";
create.storageClass = OSSBucketStorageClassIA;     // Specify the storage class here.

// Optional storage classes: OSSBucketStorageClassStandard, OSSBucketStorageClassIA, etc.

For a complete example, see Create a bucket.

API

When you call PutBucket, you can specify the storage class of the bucket in the StorageClass request element.

Storage redundancy type

The data redundancy type determines the disaster recovery level, durability, and availability of your data. The default type is zone-redundant storage. You can upgrade from locally redundant storage to zone-redundant storage, but you cannot downgrade.

  • Zone-redundant storage (ZRS) - Recommended for production environments

    Your data is stored across multiple zones (AZs) in the same region. This ensures business continuity if an entire zone fails and provides higher data durability and service availability.

  • Locally redundant storage (LRS) - For non-critical or test data

    Your data is stored redundantly within a single zone at a lower cost. It can withstand hardware failures but cannot guarantee data access if a zone fails.

Console

When you create a bucket, you can select the data redundancy type for the bucket under Storage Redundancy Type.

Use ossutil

The following command creates a bucket named examplebucket with the locally redundant storage (LRS) redundancy type.

ossutil mb oss://examplebucket --redundancy-type LRS

For more information about this command, see mb (create a bucket).

Use the OSS SDK

Java

To set the storage redundancy type, you can configure the CreateBucketRequest object as follows.

// Prepare a request object that contains the storage redundancy type.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("your-bucket-name");
createBucketRequest.setDataRedundancyType(DataRedundancyType.ZRS); // Specify the storage redundancy type here.

// Options: DataRedundancyType.ZRS, DataRedundancyType.LRS

For a complete example, see Create a bucket using OSS SDK for Java.

Python

When you call the client.put_bucket method, you can specify the storage redundancy type using the create_bucket_configuration parameter.

# Prepare a request object that contains the storage redundancy type.
req = oss.PutBucketRequest(
    bucket="your-bucket-name",
    create_bucket_configuration=oss.CreateBucketConfiguration(
        data_redundancy_type='ZRS'  # Specify the storage redundancy type here.
    )
)

# Options: 'ZRS', 'LRS'

For a complete example, see Create a bucket (Python SDK V2).

Go

To set the storage redundancy type, you can configure the CreateBucketConfiguration field when you create a PutBucketRequest.

request := &oss.PutBucketRequest{
    Bucket: oss.Ptr("your-bucket-name"),
    CreateBucketConfiguration: &oss.CreateBucketConfiguration{
        DataRedundancyType: oss.DataRedundancyZRS, // Specify the storage redundancy type here.
    },
}

// Options: oss.DataRedundancyZRS, oss.DataRedundancyLRS

For a complete example, see Create a bucket (Go SDK V2).

PHP

To set the storage redundancy type, you can pass a CreateBucketConfiguration object to the constructor when you create a PutBucketRequest object.

// Prepare a request object that contains configurations such as the storage redundancy type.
$request = new Oss\Models\PutBucketRequest(
    "your-bucket-name",
    null, // acl
    null, // resourceGroupId
    new Oss\Models\CreateBucketConfiguration(
        null,             // Specify the storage redundancy type here.
        'ZRS'
    )
);

/* 
 * Optional storage redundancy types: 'ZRS', 'LRS'
*/

For a complete example, see Create a bucket (PHP SDK V2).

C#

To set the storage redundancy type, you can create a CreateBucketRequest object and configure its properties as follows.

// Prepare a request object that contains the storage redundancy type configuration.
var request = new CreateBucketRequest("your-bucket-name");
request.DataRedundancyType = DataRedundancyType.ZRS;        // Specify the storage redundancy type here.

// Optional storage redundancy types: DataRedundancyType.ZRS, DataRedundancyType.LRS

For a complete example, see Create buckets.

Node.js

To set the storage redundancy type, you can create an options object and pass it to the putBucket method.

// Prepare an options object that contains the storage redundancy type configuration.
const options = {
  dataRedundancyType: 'LRS',    // Specify the storage redundancy type here.
};

// Optional storage redundancy types: 'ZRS', 'LRS'

For a complete example, see Create a bucket.

API

When you call PutBucket, you can specify the storage redundancy type of the bucket in the DataRedundancyType request element.

Access control list (ACL)

The access control list (ACL) controls the anonymous access policy for a bucket. The default permission is private, which you can change at any time after the bucket is created. Objects inherit the bucket's access permissions by default. You can also set permissions for individual objects.

  • Private - Strongly recommended

    This is the default and most secure setting. Only the bucket owner and users who are explicitly granted permissions through RAM policies or bucket policies can access the bucket. We recommend that you always use this setting. To grant access to other users, see Overview of permission and access control.

  • Public-read - Use with caution

    No authentication is required. Anyone, including anonymous visitors, can read objects but cannot write to them.

    • Your data will be fully public. This may result in unexpected charges for outbound traffic over the Internet. This setting is suitable for scenarios that require public sharing, such as hosting static website resources.

    • If you must enable public-read, we recommend that you configure hotlink protection to allow access only from specific sources, such as your website domain, to prevent malicious traffic consumption.

  • Public-read-write - Strongly not recommended

    Anyone can read, write, and even delete objects in the bucket. This poses an extremely high risk and can lead to substantial fees. Use this setting only for special scenarios, such as public resource repositories. This setting is strictly prohibited for general use.

Use the OSS console

For security reasons, the OSS console enables Block Public Access by default and supports creating only private buckets.

To change the ACL to public-read or public-read-write, you can perform the following steps:

  1. Click the name of the target bucket.

  2. In the navigation pane on the left, choose Access Control > Block Public Access and disable the policy.

  3. Go to the Access Control List tab and click Settings.

  4. Follow the on-screen instructions to change the bucket ACL to Public Read or Public Read/Write.

Use ossutil

The following command creates a bucket named examplebucket and sets its access control list (ACL) to private.

ossutil mb oss://examplebucket --acl=private

For more information about this command, see mb (create a bucket).

Use the OSS SDK

Java

To set the access permissions, you can configure the CreateBucketRequest object as follows.

// Prepare a request object that contains the access permissions.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("your-bucket-name");
createBucketRequest.setCannedACL(CannedAccessControlList.private); // Specify the bucket ACL here.

// Options: CannedAccessControlList.private, CannedAccessControlList.PublicRead,CannedAccessControlList.PublicReadWrite

For a complete example, see Create a bucket using OSS SDK for Java.

Python

When you call the client.put_bucket method, you can specify the access permissions using the create_bucket_configuration parameter.

# Prepare a request object that contains the access permissions.
req = oss.PutBucketRequest(
    bucket="your-bucket-name",
    create_bucket_configuration=oss.CreateBucketConfiguration(
        access_control_policy='pricate'  # Specify the access permissions here.
    )
)

# Options: 'pricate', 'public-read','public-read-write'

For a complete example, see Create a bucket (Python SDK V2).

Go

To set the access permissions, you can configure the Acl field when you create a PutBucketRequest.

// Prepare a request object that contains configurations such as access permissions.
request := &oss.PutBucketRequest{
    Bucket: oss.Ptr("your-bucket-name"),
    Acl:    oss.BucketACLPrivate, // Specify the access permissions here.
    CreateBucketConfiguration: &oss.CreateBucketConfiguration{
    },
}

// Optional access permissions: oss.BucketACLPrivate, oss.BucketACLPublicRead, oss.BucketACLPublicReadWrite

For a complete example, see Create a bucket (Go SDK V2).

PHP

To set the access permissions, you can configure the Acl field when you create a PutBucketRequest.

// Prepare a request object that contains configurations such as access permissions.
$request = new Oss\Models\PutBucketRequest(
    "your-bucket-name",
    'private', // Specify the access permissions here (second parameter).
    null,      // resourceGroupId
    new Oss\Models\CreateBucketConfiguration(
        'IA',      // Specify the storage class here.
        'ZRS'      // Specify the redundancy type here.
    )
);

/* 
 * Optional access permissions: 'private', 'public-read', 'public-read-write'
*/

For a complete example, see Create a bucket (PHP SDK V2).

C#

To set the access permissions, you can create a CreateBucketRequest object and configure its properties as follows.

// Prepare a request object that contains the access permission configuration.
var request = new CreateBucketRequest("your-bucket-name");
request.ACL = CannedAccessControlList.private;       // Specify the access permissions here.

// Optional access permissions: CannedAccessControlList.private, CannedAccessControlList.PublicRead,CannedAccessControlList.PublicReadWrite

For a complete example, see Create buckets.

Node.js

To set the access permissions, you can create an options object and pass it to the putBucket method.

// Prepare an options object that contains the access permissions.
const options = {
  acl: 'private',     // Specify the access permissions here.
};

// Optional access permissions: 'private', 'public-read','public-read-write'

For a complete example, see Create a bucket.

Android

To set the access permissions, you can create and configure a CreateBucketRequest object as follows.

// Prepare a request object that contains configurations such as access permissions.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("your-bucket-name");
createBucketRequest.setBucketACL(CannedAccessControlList.Private); // Specify the access permissions here.

// Optional access permissions: CannedAccessControlList.Private, CannedAccessControlList.PublicRead,CannedAccessControlList.PublicReadWrite

For a complete example, see Create a bucket (Android SDK).

iOS

To set the access permissions, you can create an OSSCreateBucketRequest object and configure its properties as follows.

// Prepare a request object that contains configurations such as access permissions.
OSSCreateBucketRequest *create = [OSSCreateBucketRequest new];
create.bucketName = @"your-bucket-name";
create.xOssACL = @"private";    // Specify the access permissions here.

// Optional access permissions: private,public-read, public-read-write, etc.

For a complete example, see Create a bucket.

API

When you call the PutBucket operation, you can specify the ACL of the bucket in the x-oss-acl request header.

Block Public Access

This is a global security switch that prevents accidental public exposure of data due to incorrect ACL or bucket policy configurations.

When enabled, you can create only private buckets. You cannot set public-read or public-read-write ACLs, or create bucket policies with public access semantics. By default, Block Public Access is enabled when you create a bucket in OSS. If your business requires public access, you can manually disable this feature after the bucket is created. However, for security reasons, we do not recommend that you disable it.

Optional feature configurations

You can configure these features during or after bucket creation based on your business needs.

  • Versioning

    This feature prevents accidental deletion or overwriting of data. When you upload an object with the same name, a new version is created instead of overwriting the existing one. You can restore a previous version with a single click after an accidental operation. For more information, see Versioning.

  • Server-side encryption

    This feature automatically encrypts static data. OSS encrypts data when it is written and decrypts it when it is read. We recommend that you enable at least the 'Fully managed by OSS' option. For more information, see Server-side encryption.

  • Resource group

    This feature is suitable for multi-team collaboration. You can group buckets by department or project for independent permission management and cost accounting. For more information, see Use resource groups.

  • Real-time log query

    When this feature is enabled, you can quickly query and analyze access logs in the console to see who accessed which files and when. This helps you investigate unusual access or perform user behavior analysis. For more information, see Real-time log query.

  • Scheduled backup

    This feature supports automated data backup. For more information, see Configure scheduled backup for a bucket.

  • HDFS service

    This feature is suitable for data lake scenarios. It allows big data frameworks such as Spark to directly analyze OSS data without data migration. For more information, see What is the OSS-HDFS service?.

  • Bucket tagging

    This feature facilitates batch management and cost analysis. You can classify buckets using key-value tags, such as department:research. For more information, see Manage bucket tags.

Billing description

Creating a bucket is free. You are charged for actual usage after you store data in the bucket. To avoid unnecessary fees, note the following points when you configure your bucket:

  • Match storage redundancy with resource plans
    The resource plan type must exactly match the bucket's storage redundancy type. For example, an LRS (locally redundant) resource plan cannot be used to offset the costs of a ZRS (zone-redundant) bucket, and vice versa. Confirm your selection during creation.

  • Special billing for non-Standard storage classes
    Although the Infrequent Access, Archive, Cold Archive, and Deep Cold Archive storage classes have lower unit prices, they have minimum storage durations and incur data retrieval fees.

    • Early deletion or modification: If a file is deleted or modified before its minimum storage duration is met, OSS still charges storage fees for the remaining duration.

    • Data reads: Except for the Standard storage class, accessing data in any other storage class incurs additional data retrieval fees.

  • Risks of public access
    If you set the access control list (ACL) to public-read or public-read-write, your data is exposed to the Internet. This can lead to malicious traffic consumption and result in unexpectedly high traffic fees.

FAQ

Can I change the bucket name and region after the bucket is created?

No, you cannot. The name and region cannot be changed after creation, so you must plan them in advance. To make changes, you must use data migration to copy the data from the old bucket to a new bucket with the desired settings.