Method: RightAws::S3#bucket

Defined in:
lib/s3/right_s3.rb

#bucket(name, create = false, perms = nil, headers = {}) ⇒ Object

Retrieve an individual bucket. If the bucket does not exist and create is set, a new bucket is created on S3. Launching this method with create=true may affect on the bucket’s ACL if the bucket already exists. Returns a RightAws::S3::Bucket instance or nil if the bucket does not exist and create is not set.

s3 = RightAws::S3.new(aws_access_key_id, aws_secret_access_key)
bucket1 = s3.bucket('my_awesome_bucket_1')
bucket1.keys  #=> exception here if the bucket does not exists
 ...
bucket2 = s3.bucket('my_awesome_bucket_2', true)
bucket2.keys  #=> list of keys
# create a bucket at the European location with public read access
bucket3 = s3.bucket('my-awesome-bucket-3', true, 'public-read', :location => :eu)

see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
(section: Canned Access Policies)


99
100
101
102
103
104
# File 'lib/s3/right_s3.rb', line 99

def bucket(name, create=false, perms=nil, headers={})
  headers['x-amz-acl'] = perms if perms
  @interface.create_bucket(name, headers) if create
  buckets.each { |bucket| return bucket if bucket.name == name }
  nil
end