列举桶

您可以使用 list_buckets 接口列举桶,以下代码展示如何获取桶列表:

def list_buckets(client)
  buckets = client.list_buckets.buckets
  if buckets.count.zero?
    puts 'No buckets.'
    nil
  else
    puts "#{buckets.count} buckets:"
    i = 0
    buckets.count.times do
      puts "#{i + 1}) #{buckets[i].name}"
      i += 1
    end
  end
rescue StandardError => e
  puts "Error when listing buckets: #{e.message}"
end