ruby/example_code/s3/auth_session_token_request_test.rb
def bucket_exists?(s3_client, bucket_name)
  response = s3_client.list_buckets
  response.buckets.each do |bucket|
    return true if bucket.name == bucket_name
  end
rescue StandardError => e
  puts "Error while checking whether the bucket '#{bucket_name}' " \
    "exists: #{e.message}"
end
# Checks whether a bucket exists in Amazon S3.
#
# @param s3_client [Aws::S3::Client] An initialized Amazon S3 client.
# @param bucket_name [String] The name of the bucket.
# @return [Boolean] true if the bucket exists; otherwise, false.
# @example
#   s3_client = Aws::S3::Client.new(region: 'us-west-2')
#   exit 1 unless bucket_exists?(s3_client, 'doc-example-bucket')
Checks whether a bucket exists in Amazon S3.
Checks whether a bucket exists in Amazon S3 .
def bucket_exists?(s3_client, bucket_name)
  response = s3_client.list_buckets
  response.buckets.each do |bucket|
    return true if bucket.name == bucket_name
  end
rescue StandardError => e
  puts "Error while checking whether the bucket '#{bucket_name}' " \
    "exists: #{e.message}"
end
def bucket_exists? ( s3_client , bucket_name ) response = s3_client . list_buckets response . buckets . each do | bucket | return true if bucket . name == bucket_name end rescue StandardError => e puts "Error while checking whether the bucket '#{bucket_name}' " "exists: #{e.message}" end
Checks whether a bucket exists in Amazon S3.
Checks whether a bucket exists in Amazon S3 .
true if the bucket exists; otherwise, false.
true if the bucket exists ; otherwise false .
Boolean
s3_client
An initialized Amazon S3 client.
An initialized Amazon S3 client .
bucket_name
The name of the bucket.
The name of the bucket .
example
s3_client = Aws::S3::Client.new(region: 'us-west-2') exit 1 unless bucket_exists?(s3_client, 'doc-example-bucket')
s3_client = Aws :: S3 :: Client . new ( region : ' us - west - 2 ' ) exit 1 unless bucket_exists? ( s3_client ' doc - example - bucket ' )