Create a bucket (Ruby SDK)
A bucket is a container for storing objects. All objects must be stored in a bucket. This topic describes how to create a bucket.
Notes
Starting at 10:00:00 (UTC+8) on October 13, 2025, OSS gradually enables block public access by default for buckets that are created by calling API operations or by using OSS SDKs or ossutil in all regions. For the time when the change takes effect in each region, see Announcement.
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 policies or Bucket Policy.
|
API |
Action |
Description |
|
PutBucket |
|
Creates a bucket. |
|
|
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.