All Products
Search
Document Center

Object Storage Service:Create a bucket (Ruby SDK)

Last Updated:Nov 29, 2025

A bucket is a container used to store objects in Object Storage Service (OSS). All objects in OSS are stored in buckets. This topic describes how to create a bucket.

Notes

From 10:00 (UTC+8) on October 13, 2025, OSS will implement a phased adjustment across all regions to enable Block Public Access by default for new buckets created using the API, OSS SDKs, or ossutil. For details about the exact times when the adjustment will take effect in each region, see [Official Announcement] Adjustment to the Public Access Blocking Configurations for Newly Created Buckets. Once Block Public Access is enabled, you cannot configure public access permissions, including public ACLs (public read and public read/write) and bucket policies that allows public access. You can disable this feature after the bucket is created if your business requires public access.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket policies.

API

Action

Definition

PutBucket

oss:PutBucket

Creates a bucket.

oss:PutBucketAcl

After creating a bucket, this permission is required to modify the bucket ACL.

Sample code

The following code creates a bucket named examplebucket:

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')

References

For more information about the API operation to create a bucket, see PutBucket.