Set up S3 bucket as website using ruby SDK

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

Version one of AWS SDK for Ruby has the method #configure_website for bucket objects. So something like this would work:

s3 = AWS::S3.new
b = s3.buckets.create(name, acl: :public_read)
b.configure_website do |cfg|
  cfg.options[:index_document] = { suffix: 'index.html' }
end

(the block to configure_website may be omitted if you don't need to set non-default options)


@Aljoscha AWS S3 is just a storage solution, to store all your files. It doesnt provide any kind of run time solution. You need to have a Ec2 instance to host your ruby based application or either to use ruby API. You can just host a static web site on S3 but cant run any kind of app.

链接地址: http://www.djcxy.com/p/59814.html

上一篇: 在与python26链接的visual studio中编译错误

下一篇: 使用ruby SDK将S3 bucket设置为网站