ruby/example_code/s3/s3-ruby-example-bucket-accessible.rb
def bucket_in_region?(s3_client, bucket_name, region)
  location = s3_client.get_bucket_location(bucket: bucket_name).location_constraint
  if region == location
    return true
  else
    return false
  end
rescue StandardError => e
  puts "Error accessing bucket: #{e.message}"
  return false
end
# Checks whether an Amazon Simple Storage Service (Amazon S3) bucket
#   exists in an AWS Region.
#
# Prerequisites:
#
# - An S3 bucket.
#
# @param s3_client [Aws::S3::Client] An initialized S3 client.
# @param bucket_name [String] The name of the bucket.
# @param region [Array] The Region to check for.
# @return [Boolean] true if the bucket exists in the specified Region;
#   otherwise, false.
# @example
#   exit 1 unless bucket_in_region?(
#     Aws::S3::Client.new(region: 'us-west-2'),
#     'doc-example-bucket',
#     'us-west-2'
#   )

Checks whether an Amazon Simple Storage Service (Amazon S3) bucket
exists in an AWS Region.



An S3 bucket.
Checks whether an Amazon Simple Storage Service ( Amazon S3 ) bucket exists in an AWS Region . An S3 bucket .
def bucket_in_region?(s3_client, bucket_name, region)
  location = s3_client.get_bucket_location(bucket: bucket_name).location_constraint
  if region == location
    return true
  else
    return false
  end
rescue StandardError => e
  puts "Error accessing bucket: #{e.message}"
  return false
end
def bucket_in_region? ( s3_client , bucket_name , region ) location = s3_client . get_bucket_location ( bucket : bucket_name ) . location_constraint if region == location return true else return false end rescue StandardError => e puts "Error accessing bucket: #{e.message}" return false end
Checks whether an Amazon Simple Storage Service (Amazon S3) bucket
exists in an AWS Region.
Checks whether an Amazon Simple Storage Service ( Amazon S3 ) bucket exists in an AWS Region .
true if the bucket exists in the specified Region; otherwise, false.
true if the bucket exists in the specified Region ; otherwise false .
Boolean
s3_client
An initialized S3 client.
An initialized S3 client .
bucket_name
The name of the bucket.
The name of the bucket .
region
The Region to check for.
The Region to check for .
example
exit 1 unless bucket_in_region?( Aws::S3::Client.new(region: 'us-west-2'), 'doc-example-bucket', 'us-west-2' )
exit 1 unless bucket_in_region? ( Aws :: S3 :: Client . new ( region : ' us - west - 2 ' ) ' doc - example - bucket ' ' us - west - 2 ' )