MoMolog MoMolog - 2 months ago 7x
Ruby Question

Set up S3 bucket as website using ruby SDK

I want to set up an Amazon S3 bucket as a website as described here:

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="">

res = AWS::S3::Base.request(:put, "/#{bucketname}?website", {}, body)

EDIT you could also use the fog gem to accomplish this.

storage ={
  :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")