A bucket is a container for storing objects in Object Storage Service (OSS). All objects are stored in buckets.
Usage notes
Starting at 10:00 (UTC+8) on October 13, 2025, OSS enables Block Public Access by default for new buckets created via the API, OSS SDKs, or ossutil. This applies to all regions on a rolling schedule. For the exact rollout timeline per region, see [Official Announcement] Adjustment to the Public Access Blocking Configurations for Newly Created Buckets.
When Block Public Access is enabled, you cannot set public ACLs (public read or public read/write) or bucket policies that allow public access. To allow public access, disable Block Public Access after the bucket is created.
Prerequisites
Before you begin, ensure that you have:
An Alibaba Cloud account (which has full permissions by default) or a RAM user or RAM role granted the
oss:PutBucketpermission. RAM users and RAM roles do not have any permissions by default and must be explicitly granted access.The
oss:PutBucketAclpermission if you plan to modify the bucket ACL after creationThe
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables configured with your AccessKey ID and AccessKey Secret
For details on granting permissions, see RAM Policy or Bucket policies.
Create a bucket
The following example creates a bucket named examplebucket in the China (Hangzhou) region.
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
# Replace with the endpoint for your target region.
# Endpoint format: https://oss-{region-id}.aliyuncs.com
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
# Read credentials from environment variables.
# Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
client.create_bucket('examplebucket')API reference
For the underlying API operation, see PutBucket.