A bucket is the primary container in OSS for storing objects. It has unlimited capacity and scales elastically.
Basic configuration
A bucket's core settings cannot be changed after creation.
-
Bucket name: Must be globally unique. Use a name that reflects your department or business for easy identification. Example:
hr-documents. -
Region: Determines the physical location of your data. Select a region based on these priorities:
-
Compliance: Select a region that meets your regulatory requirements.
-
Performance: Select the region closest to your end users. If your data is accessed by Alibaba Cloud products such as ECS, select the same region to use the free internal network and reduce latency.
-
Feature support: Check theRelease notes to confirm that the region supports the features you need.
-
Cost: After satisfying the preceding requirements, choose a region with lower costs.
NoteYou cannot create new buckets in the China (Zhangjiakou) region. Existing buckets in this region remain fully functional. If you have a resource plan for this region, it can still be used to offset the costs of your existing buckets.
-
If you specify only the bucket name and region, OSS applies these defaults: Standard storage class, Zone-Redundant Storage (ZRS), private ACL, and Block Public Access enabled.
Console
-
On the Buckets page of the OSS console, click Create Bucket.
-
In the Create Bucket panel, set the Bucket Name and Region, and then click Create at the bottom.
ossutil
Create buckets from the command line. Install ossutil.
-
Configure the region for the bucket.
ossutil config -
Press Enter to skip previous settings until the region prompt appears:
Please enter Region [cn-hangzhou]:Enter a region ID (e.g.,
cn-beijing) and press Enter, or press Enter to use the default (cn-hangzhou). Available region IDs: OSS Region List. -
Create a bucket named
examplebucket.ossutil mb oss://examplebucket -
Verify that the bucket was created successfully.
ossutil ls
Full command syntax and options:mb (create a bucket).
SDK
These code samples create a bucket with common SDKs. Other SDKs are covered in theSDK introduction.
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.DataRedundancyType;
import com.aliyun.oss.model.StorageClass;
public class CreateBucket {
public static void main(String[] args) throws Exception {
// Set yourEndpoint to the Endpoint of the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Obtain access credentials from environment variables. Before you run this 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 bucket name.
String bucketName = "examplebucket";
// Specify the resource group ID. If you do not specify a resource group ID, the bucket belongs to the default resource group.
//String rsId = "rg-aek27tc****";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// When the OSSClient instance is no longer in use, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Create a CreateBucketRequest object.
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
// To specify the storage class, access control list (ACL), and data redundancy type when you create the bucket, see the following code.
// This example shows how to set the storage class of the bucket to Standard.
//createBucketRequest.setStorageClass(StorageClass.Standard);
// The default data redundancy type is locally redundant storage (LRS), which is DataRedundancyType.LRS. To set the data redundancy type to zone-redundant storage (ZRS), set it to DataRedundancyType.ZRS.
//createBucketRequest.setDataRedundancyType(DataRedundancyType.ZRS);
// 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);
// Create the 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(®ion, "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;
// Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, if the bucket is 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 bucket name.
var bucketName = "examplebucket";
// Specify the region where the bucket is located. For example, if the bucket is 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 as needed.
var conf = new ClientConfiguration();
// Use Signature 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) to public-read. The default ACL is private.
request.ACL = CannedAccessControlList.PublicRead;
// Set the data disaster recovery type to zone-redundant storage.
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(
# The following example uses the endpoint of the China (Hangzhou) region. Replace the endpoint with the actual one.
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 bucket name. Example: examplebucket.
client.create_bucket('examplebucket')// Construct a request to create a bucket.
// Specify the bucket name.
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) {
// Request exception.
if (clientException != null) {
// Client-side exceptions, such as network errors.
clientException.printStackTrace();
}
if (serviceException != null) {
// Server-side 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 the OSS account information. */
/* Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
std::string Endpoint = "yourEndpoint";
/* Set yourRegion to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Region to cn-hangzhou. */
std::string Region = "yourRegion";
/* Specify the bucket name, for example, examplebucket. */
std::string BucketName = "examplebucket";
/* Initialize network resources. */
InitializeSdk();
ClientConfiguration conf;
conf.signatureVersion = SignatureVersionType::V4;
/* Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. */
auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
OssClient client(Endpoint, credentialsProvider, conf);
client.SetRegion(Region);
/* Specify the name, storage class, and ACL for the new bucket. */
CreateBucketRequest request(BucketName, StorageClass::IA, CannedAccessControlList::PublicReadWrite);
/* Set the data redundancy type to zone-redundant storage. */
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 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;
}];
// Block the current thread to wait for the task to complete.
// [createTask waitUntilFinished]; #include "oss_api.h"
#include "aos_http_io.h"
/* Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* Specify the bucket name. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Set yourRegion to the region where the bucket is located. For example, if the bucket is 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);
/* Initialize the aos_string_t type with a char* string. */
aos_str_set(&options->config->endpoint, endpoint);
/* Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. */
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"));
// Configure the following two parameters.
aos_str_set(&options->config->region, region);
options->config->signature_version = 4;
/* Specifies whether to use a CNAME to access OSS. A value of 0 indicates that a CNAME is not used. */
options->config->is_cname = 0;
/* Set network parameters, such as the timeout period. */
options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
/* At the program entry point, call the aos_http_io_initialize method to initialize global resources such as the network and memory. */
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
exit(1);
}
/* The memory pool for memory management is equivalent to apr_pool_t. The implementation code is in the apr library. */
aos_pool_t *pool;
/* Create a new memory pool. The second parameter is NULL, which indicates that the new pool does not inherit from another memory pool. */
aos_pool_create(&pool, NULL);
/* Create and initialize options. This parameter includes global configuration information, such as the endpoint, access_key_id, access_key_secret, is_cname, and curl. */
oss_request_options_t *oss_client_options;
/* Allocate memory for options in the memory pool. */
oss_client_options = oss_request_options_create(pool);
/* Initialize the client options oss_client_options. */
init_options(oss_client_options);
/* Initialize 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 the char* data to the aos_string_t bucket. */
aos_str_set(&bucket, bucket_name);
/* Create the bucket. */
resp_status = oss_create_bucket(oss_client_options, &bucket, oss_acl, &resp_headers);
/* Check whether the request was successful. */
if (aos_status_is_ok(resp_status)) {
printf("create bucket succeeded\n");
} else {
printf("create bucket failed\n");
}
/* Release the memory pool. This releases the memory allocated for various resources during the request. */
aos_pool_destroy(pool);
/* Release the previously allocated global resources. */
aos_http_io_deinitialize();
return 0;
}API
When you call the PutBucket operation, specify the bucket 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 is Standard. Each lower tier reduces storage cost but adds access restrictions.
Objects inherit their bucket's storage class. You cannot change a bucket's storage class after creation, but lifecycle rules can transition objects to lower-cost tiers automatically.
-
Standard
Best for active data accessed more than once a month, with real-time access. Choose Standard if you are unsure about access patterns — use lifecycle rules later to transition objects to lower-cost tiers.
-
Infrequent Access (IA):
For warm data accessed monthly or less (backups, logs). Real-time access, 30-day minimum storage duration. Early deletion incurs full-duration charges. Not for temporary or test data.
-
Archive:
For cold data accessed less than once per 90 days. Supports real-time access via archive direct read, or restore before reading (~1 minute). Minimum storage duration: 60 days.
Restoration: Making archived data temporarily readable after a waiting period.
-
Cold Archive
For data accessed less than once a year. Requires restoration (1–12 hours) before reading. Lower cost, 180-day minimum storage duration.
-
Deep Cold Archive
Lowest-cost tier for data accessed less than once a year. Restoration takes 12 or 48 hours, with a 180-day minimum storage duration. Do not set this as the default storage class for new buckets. Use lifecycle rules to transition data to this tier instead.
Console
Select the storage class when creating the bucket.
ossutil
Create a bucket named examplebucket with IA storage class:
ossutil mb oss://examplebucket --storage-class IA
Full command syntax and options:mb (create a bucket).
OSS SDK
These code samples create a bucket with common SDKs. Other SDKs are covered in theSDK introduction.
Java
To set the storage class, 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.
Complete example:Create a bucket (Java SDK V1).
Python
When you call the client.put_bucket method, 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'
Complete example:Create a bucket (Python SDK V2).
Go
To set the storage class, 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.
Complete example:Create a bucket (Go SDK V2).
PHP
To set the storage class, 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'
*/
Complete example:Create a bucket (PHP SDK V2).
C#
To set the storage class, 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.
Complete example:Create a bucket (C# SDK V1).
Node.js
To set the storage class, 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'
Complete example:Create a bucket (Node.js SDK).
Android
To set the storage class or access control list, create a CreateBucketRequest object and configure it 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.
Complete example:Create a bucket (Android SDK).
iOS
To set the storage class, create an OSSCreateBucketRequest object and configure its properties as follows.
// 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.
Complete example:Create a bucket (iOS SDK).
API
When you call PutBucket, specify the storage class of the bucket in the StorageClass request element.
Storage redundancy type
Controls data durability, availability, and disaster recovery. Default: ZRS. You can upgrade from LRS to ZRS, but cannot downgrade.
-
Zone-Redundant Storage (ZRS) - Recommended for production environments
Stores data across multiple availability zones (AZs) in the same region, ensuring business continuity even if an entire AZ fails.
-
Locally Redundant Storage (LRS) - For non-critical or test data
Stores data redundantly within a single AZ at lower cost. Protects against hardware failures but cannot guarantee access if the entire AZ becomes unavailable.
Console
Select the redundancy type when creating the bucket.
ossutil
Create a bucket named examplebucket with LRS redundancy:
ossutil mb oss://examplebucket --redundancy-type LRS
Full command syntax and options:mb (create a bucket).
OSS SDK
Java
To set the storage redundancy type, 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
Complete example:Create a bucket (Java SDK V1).
Python
When you call the client.put_bucket method, use the create_bucket_configuration parameter to specify the storage redundancy type.
# 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'
Complete example:Create a bucket (Python SDK V2).
Go
To set the storage redundancy type, when you create a PutBucketRequest, configure the CreateBucketConfiguration field.
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
Complete example:Create a bucket (Go SDK V2).
PHP
To set the storage redundancy type, 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, // storageClass
'ZRS' // Specify the storage redundancy type here.
)
);
/*
* Optional storage redundancy types: 'ZRS', 'LRS'
*/
Complete example:Create a bucket (PHP SDK V2).
C#
To set the storage redundancy type, 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
Complete example:Create a bucket (C# SDK V1).
Node.js
To set the storage redundancy type, 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'
Complete example:Create a bucket (Node.js SDK).
API
When you call PutBucket, specify the storage redundancy type of the bucket in the DataRedundancyType request element.
Access control list (ACL)
The ACL controls access to a bucket and its objects. The default is private, changeable after creation. Objects inherit the bucket's ACL, or you canset permissions for individual objects.
-
Private - Strongly recommended
Default and most secure. Only the bucket owner and explicitly authorized users (via RAM or bucket policies) can access the bucket. Recommended for all use cases. Grant access to others throughOverview of permissions and access control.
-
Public read - Use with caution
Anyone can read objects without authentication.
-
Data becomes fully public, which may cause unexpected outbound traffic charges. Use only for public content such as static website assets.
-
If public read is needed, configurehotlink protection to restrict access to specific referrers and prevent unauthorized traffic.
-
-
Public read/write - Strongly Discouraged
Anyone can read, write, and delete objects. Extreme security risk with potential for substantial fees. Use only for special cases such as public repositories.
Console
For security reasons, the OSS console enables Block Public Access by default and only allows creating private buckets.
To set a public ACL:
-
Click the name of the target bucket to go to its details page.
-
In the navigation pane on the left, choose Permissions > Block Public Access, and turn off this policy.
-
Switch to the ACL tab and click Configure.
-
Follow the on-screen instructions to change the bucket's ACL to Public Read or Public Read/Write.
ossutil
Create a bucket named examplebucket with private ACL:
ossutil mb oss://examplebucket --acl=private
Full command syntax and options:mb (create a bucket).
OSS SDK
Java
To set the access control list, 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
Complete example:Create a bucket (Java SDK V1).
Python
When you call the client.put_bucket method, specify the access control list in 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='private' # Specify the access permissions here.
)
)
# Options: 'private', 'public-read', 'public-read-write'
Complete example:Create a bucket (Python SDK V2).
Go
To set the access control list, when you create a PutBucketRequest , configure theAcl field.
// 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
Complete example:Create a bucket (Go SDK V2).
PHP
To set the access control list, 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'
*/
Complete example:Create a bucket (PHP SDK V2).
C#
To set the access control list, 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
Complete example:Create a bucket (C# SDK V1).
Node.js
To set access permissions, 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'
Complete example:Create a bucket (Node.js SDK).
Android
To set the access control list, create a CreateBucketRequest object and configure it 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
Complete example:Create a bucket (Android SDK).
iOS
To set the access permissions, 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.
Complete example:Create a bucket (iOS SDK).
API
When you call PutBucket, specify bucket permissions in the x-oss-acl request header.
Block Public Access
A global security switch that prevents unintended data exposure from misconfigured ACLs or bucket policies.
When enabled, only private buckets can be created and public ACLs or policies are blocked. Enabled by default. You can disable it after creation, but keeping it enabled is strongly recommended.
Optional features
You can configure these features as needed during or after bucket creation.
-
Versioning
Prevents accidental data loss. Uploading an object with the same name creates a new version instead of overwriting. Restore any previous version to recover from errors.Versioning.
-
Server-side encryption
Encrypts data at rest automatically — OSS encrypts on write and decrypts on read. Enable at least the OSS-Managed option.Server-side encryption.
-
Resource group
Group buckets by department or project for separate permission management and cost accounting.Use resource groups.
-
Real-time log query
Query and analyze bucket access logs in the console. Track who accessed which objects and when to investigate unusual activity or analyze usage.Real-time log query.
-
Scheduled backup
Automates data backup on a schedule.Configure scheduled backup for a bucket.
-
OSS-HDFS service
Enables big data frameworks like Spark to analyze data in OSS directly, without migration.What is the OSS-HDFS service?
-
Bucket tag
Classify buckets with key-value tags such as
Department:R&Dfor batch management and cost analysis. Manage bucket tags.
Billing
Creating a bucket is free. You are charged based on actual storage usage. To avoid unnecessary costs:
-
Resource plan compatibility
Your resource plan type must match the bucket's storage redundancy type. An LRS resource plan cannot offset ZRS bucket costs, and vice versa. -
Special billing for non-Standard storage classes
IA, Archive, Cold Archive, and Deep Cold Archive offer lower unit prices but impose minimum storage durations anddata retrieval fees.-
Early deletion or modification: If you delete or modify an object before its minimum storage duration ends, you are charged for the full minimum duration.
-
Data reads: Accessing data in any storage class other than Standard incurs an additional data retrieval fee.
-
-
Risks of public access
Setting the ACL to public read or public read/write exposes data to the internet, risking unauthorized hotlinking and unexpectedly high traffic fees.