I want to set up an Amazon S3 bucket as a website as described here:
http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTwebsite.html?r=5271
but using an ruby API, preferably the aws-sdk for ruby. Is there a possibility to do that / a library that already supports that? Could not find anything in aws-sdk and right-aws, but maybe I was just blind?
It is possible to configure your bucket as website using an ruby API. I did found a solution, but this uses the aws-s3
gem, not the aws-sdk
gem. I found this solution in the ponyhost gem:
body = '<?xml version="1.0" encoding="UTF-8"?>
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<IndexDocument><Suffix>index.html</Suffix></IndexDocument>
<ErrorDocument><Key>404.html</Key></ErrorDocument>
</WebsiteConfiguration>'
res = AWS::S3::Base.request(:put, "/#{bucketname}?website", {}, body)
EDIT you could also use the fog
gem to accomplish this.
storage = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'YOUR_KEY',
:aws_secret_access_key => 'YOUR_SECRET',
:region => 'eu-west-1'
})
if storage.kind_of?(Fog::Storage::AWS::Real)
storage.put_bucket_website("YOUR_BUCKET", "index.html", :key => "404.html")
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With