AWS SDK for Ruby
Developer Guide

Getting Information about All Amazon S3 Buckets

The following example lists the names of up to 50 of your Amazon S3 buckets. Copy the code and save it as buckets.rb. Notice that although the Resource object is created in the us-west-2 region, Amazon S3 returns buckets to which you have access, regardless of the region they are in.

require 'aws-sdk-s3' # v2: require 'aws-sdk' region = 'us-west-2' s3 = region) s3.buckets.limit(50).each do |b| puts "#{}" end


When you specify a region, the buckets method calls the Client#list_buckets method, which returns a list of all buckets owned by the authenticated sender of the request. See Getting Information about All Amazon S3 Buckets in a Region to learn how to filter this list to get the buckets only in a specific region.