A bucket is a container that stores objects in OSS. All objects must belong to a bucket.
Prerequisites
Before you begin, make sure you have:
The
oss:PutBucketpermission on your Alibaba Cloud account. RAM users and RAM roles have no permissions by default — grant access via RAM Policy or Bucket policies.The
oss:PutBucketAclpermission if you need to modify the bucket's Access Control List (ACL) after creation.An OSS endpoint for the target region. The sample code uses the public endpoint for China (Hangzhou):
https://oss-cn-hangzhou.aliyuncs.com. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. See Regions and endpoints.An OSSClient instance initialized with an OSS endpoint. To initialize the client with a custom domain name or Security Token Service (STS), see Initialization.
The
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables set with valid credentials.
Starting October 13, 2025, at 10:00 (UTC+8), OSS enables Block Public Access by default for new buckets created via the API, OSS SDKs, or ossutil. The rollout is phased across regions — see [Official Announcement] Adjustment to the Public Access Blocking Configurations for Newly Created Buckets for the schedule. When Block Public Access is enabled, you cannot set public ACLs (public read or public read/write) or bucket policies that allow public access. If your application requires public access, disable Block Public Access after the bucket is created.
How it works
The C SDK creates a bucket in four steps:
Call
aos_http_io_initialize()to initialize global resources (network, memory).Create a memory pool with
aos_pool_create()and configure client options (endpoint, credentials, region, signature version).Call
oss_create_bucket()with the bucket name and ACL.Release resources with
aos_pool_destroy()andaos_http_io_deinitialize().
Sample code
#include "oss_api.h"
#include "aos_http_io.h"
/* Replace yourEndpoint with the endpoint for your region.
Example for China (Hangzhou): https://oss-cn-hangzhou.aliyuncs.com */
const char *endpoint = "yourEndpoint";
/* Replace examplebucket with your bucket name. */
const char *bucket_name = "examplebucket";
/* Replace yourRegion with the region ID.
Example for China (Hangzhou): cn-hangzhou */
const char *region = "yourRegion";
void init_options(oss_request_options_t *options)
{
options->config = oss_config_create(options->pool);
/* Bind the endpoint string to the config. */
aos_str_set(&options->config->endpoint, endpoint);
/* Read credentials from environment variables.
Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running. */
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"));
/* Set the region and use Signature Version 4. */
aos_str_set(&options->config->region, region);
options->config->signature_version = 4;
/* Set is_cname to 0 to use the standard OSS endpoint (not a CNAME). */
options->config->is_cname = 0;
/* Configure network settings such as the timeout period. */
options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
/* Initialize global resources (network, memory). */
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
exit(1);
}
/* Create a memory pool for this request. */
aos_pool_t *pool;
aos_pool_create(&pool, NULL);
/* Initialize client options. */
oss_request_options_t *oss_client_options;
oss_client_options = oss_request_options_create(pool);
init_options(oss_client_options);
/* Set up 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;
aos_str_set(&bucket, bucket_name);
/* Create the bucket. */
resp_status = oss_create_bucket(oss_client_options, &bucket, oss_acl, &resp_headers);
if (aos_status_is_ok(resp_status)) {
printf("create bucket succeeded\n");
} else {
printf("create bucket failed\n");
}
/* Release resources. */
aos_pool_destroy(pool);
aos_http_io_deinitialize();
return 0;
}What's next
For the full API reference, see PutBucket.