A bucket is a container that is used to store objects in Object Storage Service (OSS). All objects in OSS are contained in buckets. Bucket names are listed in alphabetical order. You can list buckets that belong to the current Alibaba Cloud account in all regions and meet the specific conditions.

List all buckets that belong to an Alibaba Cloud account

The following code provides an example on how to list buckets that belong to the current Alibaba Cloud account in all regions:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
# List all buckets that belong to the current Alibaba Cloud account in all regions. 
buckets = client.list_buckets
buckets.each { |b| puts b.name }

List buckets that contain a specified prefix in their names

The following code provides an example on how to list buckets that contain the example prefix in their names and belong to the current Alibaba Cloud account in all regions:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
# List buckets that contain the specified prefix in their names and belong to the current Alibaba Cloud account in all regions. 
buckets = client.list_buckets(:prefix => 'example')
buckets.each { |b| puts b.name }

References

For more information about the API operation that you can call to list buckets, see GetService (ListBuckets).