S3

S3 gem provides access to Amazon’s Simple Storage Service. It supports both: European and US buckets through REST API.

Installation

To install the gem type:

gem install s3 --source http://gemcutter.org

Usage

require "s3"
service = S3::Service.new(:access_key_id => "...",
                          :secret_access_key => "...")
#=> #<S3::Service:...>

service.buckets
#=> [#<S3::Bucket:first-bucket>,
#    #<S3::Bucket:second-bucket>]

first_bucket = service.buckets.find("first-bucket")
#=> #<S3::Bucket:first-bucket>

first_bucket.objects
#=> [#<S3::Object:/first-bucket/lenna.png>,
#    #<S3::Object:/first-bucket/lenna_mini.png>]

object = first_bucket.objects.find("lenna.png")
#=> #<S3::Object:/first-bucket/lenna.png>

object.content_type
#=> "image/png"

object.content
#=> "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00..."

object.destroy
#=> true

new_object = bucket.objects.build("bender.png")
#=> #<S3::Object:/synergy-staging/bender.png>

new_object.content = open("bender.png")

new_object.save
#=> true

Command line tool usage

You have to pass access key id (-a) and secret access key (-s) to the command line tool. S3 reads ACCESS_KEY_ID and SECRET_ACCESS_KEY environment variables and uses them by default, so if you don’t want to pass them each time, export them (e.g. in ~/.bashrc file).

You can also pass --help to the commmands like:
s3 bucket add --help
s3 object show --help

See also

Copyright

Copyright © 2009 Jakub Kuźma, Mirosław Boruta. See LICENSE for details.