AWS S3 using AWS/S3 Ruby gem

working on storing files to Amazon’s S3 web service. Here’s what I’ve come up with so far:

1
2
3
4
5
6
7
8
9
10
11
12
require 'aws/s3'
def aws_connect
  @aws_connect ||= AWS::S3::Base.establish_connection!(
    :access_key_id=>AWS_KEY,
    :secret_access_key=>AWS_SECRET
  )
end
 
def aws_upload(file,bucket=AWS_BUCKET)
  aws_connect
  AWS::S3::S3Object.store(file,open(file),bucket)
end

then a:

1
aws_upload('test.txt')

Will upload the the file to the Amazon bucket. Pretty simple.

Posted: March 22nd, 2010 | Author: jay | Filed under: Code | Tags: , , , , , , , , | No Comments »