A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to list buckets.

The following code provides an example on how to call Client#list_buckets to list all buckets of the current user and specify :prefix to list buckets whose names contain a specified prefix:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

buckets = client.list_buckets
buckets.each { |b| puts b.name }

buckets = client.list_buckets(:prefix => 'my-')
buckets.each { |b| puts b.name }

For more information about how to list buckets, see GetBucket (ListObjects).