AWS SDK for Ruby
Developer Guide

Getting Information about All Amazon S3 Buckets in a Region

The following example lists the names of the first 50 buckets for the us-west-2 region. If you don't specify a limit, Amazon S3 lists all buckets in us-west-2.

require 'aws-sdk-s3' # v2: require 'aws-sdk' region = 'us-west-2' s3 = Aws::S3::Resource.new(region: region) s3.buckets.limit(50).each do |b| if s3.client.get_bucket_location(bucket: b.name).location_constraint == region puts "#{b.name}" end end

Note

If a bucket is not in the region in which you instantiated your Resource object, the SDK emits a warning message when you call get_bucket_location. You can suppress this message by redirecting STDERR.

On Windows, append 2> nul to the command.

On Linux or iOS, append 2> /dev/null to the command.