Skip to content

Instantly share code, notes, and snippets.

@hjblok
Created September 13, 2012 06:25
Show Gist options
  • Save hjblok/3712325 to your computer and use it in GitHub Desktop.
Save hjblok/3712325 to your computer and use it in GitHub Desktop.
Method to set website configuration on Amazon S3 bucket using aws-sdk
require 'rubygems'
require "aws-sdk"
module AWS
class S3
# Client class for Amazon Simple Storage Service (S3).
class Client < Core::Client
# @overload set_bucket_website(options = {})
# @param [Hash] options
# @option options [required,String] :bucket_name
# @option options [required,String] :index_document
# @option options [required,String] :error_document
# @return [Core::Response]
bucket_method(:set_bucket_website, :put, 'website') do
configure_request do |req, options|
index_document = options[:index_document]
error_document = options[:error_document]
# unless state =~ /^(Enabled|Suspended)$/
# raise ArgumentError, "invalid versioning state `#{state}`"
# end
super(req, options)
req.body = <<-XML.strip
<WebsiteConfiguration xmlns="#{XMLNS}">
<IndexDocument>
<Suffix>#{index_document}</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>#{error_document}</Key>
</ErrorDocument>
</WebsiteConfiguration>
XML
end
end
end
end
end
s3 = AWS::S3.new()
res = s3.client.set_bucket_website(:bucket_name => bucket_name, :index_document => "index.html", :error_document => "404.html")
puts res.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment