2011-04-08
I haven't written a blog post since I made a blog so I decided that I'm going to always write a blog post on Friday even if I have nothing to write about.
This week: an awesome script.
This little snippet of ruby (combined with the S3 gem) will print a random number to a file, upload the file to S3, and return the URL.
KEY = 'KEY'
SECRET = 'SECRET'
require 'aws/s3'
AWS::S3::Base.establish_connection!(
:access_key_id => KEY,
:secret_access_key => SECRET
)
class Bucket < AWS::S3::S3Object
set_current_bucket_to 'test'
end
n = rand(5)
$stderr.puts n
Bucket.store('sample.txt', n.to_s)
puts Bucket.find('sample.txt').url
Invoke thusly,
curl `ruby s3.rb`
5
5
Isn't that just awesome?
See you next Friday.