All Products
Search
Document Center

Object Storage Service:Create a bucket (C# SDK V1)

Last Updated:Mar 20, 2026

A bucket is a container for storing objects in Object Storage Service (OSS). All objects in OSS must belong to a bucket. This topic shows how to create a bucket using the OSS SDK for C#.

How it works

Creating a bucket with the C# SDK requires two steps: configure an OSSClient instance with your endpoint and credentials, then call CreateBucket with a CreateBucketRequest. The request lets you set the access control list (ACL) and data redundancy type at creation time.

Prerequisites

Before you begin, ensure that you have:

  • An initialized OSSClient. If you want to create an OSSClient instance using custom domain names or Security Token Service (STS), see Initialization.

  • The oss:PutBucket permission on your Alibaba Cloud account, RAM user, or RAM role. Grant permissions through RAM Policy or Bucket policies.

  • The oss:PutBucketAcl permission if you need to set or modify the bucket ACL.

Usage notes

  • The examples in this topic use the public endpoint for the China (Hangzhou) region (https://oss-cn-hangzhou.aliyuncs.com). To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead. For a full list of endpoints, see Regions and endpoints.

  • Starting at 10:00 (UTC+8) on October 13, 2025, OSS enables Block Public Access by default for new buckets created through the API, OSS SDKs, or ossutil. With Block Public Access enabled, public ACLs (public-read and public read/write) and bucket policies that allow public access cannot be applied. If your use case requires public access, disable Block Public Access after creating the bucket. For the rollout schedule by region, see [Official Announcement] Adjustment to the Public Access Blocking Configurations for Newly Created Buckets.

Create a bucket

The following example creates a bucket named examplebucket in the China (Hangzhou) region, sets its ACL to public-read, and configures zone-redundant storage (ZRS).

using Aliyun.OSS;
using Aliyun.OSS.Common;

// Replace with the endpoint for your bucket's region.
// Example: https://oss-cn-hangzhou.aliyuncs.com
var endpoint = "yourEndpoint";

// Load access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this example.
var accessKeyId = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_ID");
var accessKeySecret = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET");

var bucketName = "examplebucket";

// Set the region that matches your endpoint. Example: cn-hangzhou
const string region = "cn-hangzhou";

// Create a ClientConfiguration instance. Use Signature V4.
var conf = new ClientConfiguration();
conf.SignatureVersion = SignatureVersion.V4;

// Create an OSSClient instance and set the region.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
client.SetRegion(region);

try
{
    var request = new CreateBucketRequest(bucketName);

    // Set the ACL. The default ACL is private.
    request.ACL = CannedAccessControlList.PublicRead;

    // Set the data redundancy type 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);
}

Key parameters

ParameterDescriptionExample
endpointThe endpoint for the region where the bucket will be created.https://oss-cn-hangzhou.aliyuncs.com
regionThe region ID corresponding to the endpoint. Must match the endpoint.cn-hangzhou
bucketNameThe name of the bucket to create.examplebucket
ACLThe bucket ACL. Default is private.CannedAccessControlList.PublicRead
DataRedundancyTypeThe data redundancy type.DataRedundancyType.ZRS

Permissions

API operationRequired actionDescription
PutBucketoss:PutBucketCreates a bucket
oss:PutBucketAclRequired to set or modify the bucket ACL after creation

By default, an Alibaba Cloud account has full permissions on its own resources. RAM users and RAM roles have no permissions by default and must be granted access through RAM Policy or bucket policies.

What's next

  • For the complete sample code, see GitHub.

  • For details about the PutBucket API operation, see PutBucket.