ruby/example_code/s3/s3_ruby_bucket_website.rb
def bucket_website_configured?(
  s3_client,
  bucket_name,
  index_document,
  error_document
)
  s3_client.put_bucket_website(
    bucket: bucket_name,
    website_configuration: {
      index_document: {
        suffix: index_document
      },
      error_document: {
        key: error_document
      }
    }
  )
  return true
rescue StandardError => e
  puts "Error configuring bucket as a static website: #{e.message}"
  return false
end
# Prerequisites:
#
# - An Amazon S3 bucket.
# - A file in the bucket representing the website's home or
#     default page.
# - A file in the bucket representing the website's error page.
#
# @param s3_client [Aws::S3::Client] An initialized Amazon S3 client.
# @param bucket_name [String] The name of the bucket.
# @param index_document [String] The file name of the home or default page
#   of the website.
# @param error_document [String] The file name of the page returned when a
#   website error occurs.
# @return [Boolean] true if the bucket was successfully configured;
#   otherwise, false.
# @example
#   exit 1 unless bucket_website_configured?(
#     Aws::S3::Client.new(region: 'us-west-2'),
#     'doc-example-bucket',
#     'index.html',
#     '404.html'
#   )

An Amazon S3 bucket.
A file in the bucket representing the website's home or
default page.
A file in the bucket representing the website's error page.
An Amazon S3 bucket . A file in the bucket representing the website ' s home or default page . A file in the bucket representing the website ' s error page .
def bucket_website_configured?(
  s3_client,
  bucket_name,
  index_document,
  error_document
)
  s3_client.put_bucket_website(
    bucket: bucket_name,
    website_configuration: {
      index_document: {
        suffix: index_document
      },
      error_document: {
        key: error_document
      }
    }
  )
  return true
rescue StandardError => e
  puts "Error configuring bucket as a static website: #{e.message}"
  return false
end
def bucket_website_configured? ( s3_client , bucket_name , index_document , error_document ) s3_client . put_bucket_website ( bucket : bucket_name , website_configuration : { index_document : { suffix : index_document } , error_document : { key : error_document } } ) return true rescue StandardError => e puts "Error configuring bucket as a static website: #{e.message}" return false end
Prerequisites:
 An Amazon S3 bucket.
Prerequisites : An Amazon S3 bucket .
true if the bucket was successfully configured; otherwise, false.
true if the bucket was successfully configured ; 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 .
index_document
The file name of the home or default page of the website.
The file name of the home or default page of the website .
error_document
The file name of the page returned when a website error occurs.
The file name of the page returned when a website error occurs .
example
exit 1 unless bucket_website_configured?( Aws::S3::Client.new(region: 'us-west-2'), 'doc-example-bucket', 'index.html', '404.html' )
exit 1 unless bucket_website_configured? ( Aws :: S3 :: Client . new ( region : ' us - west - 2 ' ) ' doc - example - bucket ' ' index . html ' ' 404 . html ' )