require 'fog'
require 'nokogiri'
# build the xml
builder = Nokogiri::XML::Builder.new do |xml|
xml.root do
xml.foo 'bar'
end
end
# log in to S3 and save it
storage = Fog::Storage.new :provider => 'AWS',
:aws_access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
dir = storage.directories.get 'my_bucket'
dir.files.create :key => 'huge.xml', :body => builder.to_xml
Notice the Amazon credentials are in environmental variables rather than coded in. This will protect you from accidentally giving them away (leaving them in a public git repo for example)
No comments:
Post a Comment