Class Aws::S3::Bucket
In: lib/s3/bucket.rb
Parent: Object

Methods

Attributes

creation_date  [R] 
name  [R] 
owner  [R] 
s3  [R] 

Public Class methods

Create a Bucket instance. 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 Bucket instance or nil if the bucket does not exist and create is not set.

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

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

Create a bucket instance. In normal use this method should not be called directly. Use Aws::S3::Bucket.create or Aws::S3.bucket instead.

Public Instance methods

Remove all keys from a bucket. Returns true.

 bucket.clear #=> true

Create an object copy. Returns a destination Aws::S3::Key instance.

 new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log')   #=> #<Aws::S3::Key:0xb7b1e240 ... >
 puts key.name   #=> 'logs/today/2.log'
 key.exists?     #=> true

Delete a bucket. Bucket must be empty. If force is set, clears and deletes the bucket. Returns true.

 bucket.delete(true) #=> true

Delete all keys where the ‘folder_key’ can be interpreted as a ‘folder’ name. Returns an array of string keys that have been deleted.

 bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
 bucket.delete_folder('test')               #=> ['test','test/2/34','test/3']

Deletes an object from s3 in this bucket.

Disables S3 server access logging on a bucket. Takes no arguments.

Enables S3 server access logging on a bucket. The target bucket must have been properly configured to receive server access logs.

 Params:
  :targetbucket - either the target bucket object or the name of the target bucket
  :targetprefix - the prefix under which all logs should be stored

 bucket.enable_logging(:targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/")
   => true
full_name()

Alias for to_s

Retrieve object data from Amazon. The key is a String or Key. Returns data.

 data = bucket.get('logs/today/1.log') #=>
 puts data #=> 'sasfasfasdf'

Retrieve object data from Amazon. The key is a String or Key. Returns Key instance.

 key = bucket.get('logs/today/1.log') #=>
 puts key.data #=> 'sasfasfasdf'

Return a list of grantees.

Retrieve key information from Amazon. The key_name is a String or Key instance. Retrieves meta-header information if head is true. Returns new Key instance.

 key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
  # is the same as:
 key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
 key.head

Retrieve a group of keys from Amazon. options is a hash: { ‘prefix’=>’’, ‘marker’=>’’, ‘max-keys’=>5, ‘delimiter’=>’’ }). Retrieves meta-headers information if head it true. Returns an array of Key instances.

 bucket.keys                     #=> # returns all keys from bucket
 bucket.keys('prefix' => 'logs') #=> # returns all keys that starts with 'logs'

Same as keys method but return an array of [keys, service_data]. where service_data is a hash with additional output information.

 keys, service = bucket.keys_and_service({'max-keys'=> 2, 'prefix' => 'logs'})
 p keys    #=> # 2 keys array
 p service #=> {"max-keys"=>"2", "prefix"=>"logs", "name"=>"my_awesome_bucket", "marker"=>"", "is_truncated"=>true}

Returns the bucket location

Retrieves the logging configuration for a bucket. Returns a hash of {:enabled, :targetbucket, :targetprefix}

  bucket.logging_info()
  => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}

Move an object to other location. Returns a destination Aws::S3::Key instance.

 new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log')   #=> #<Aws::S3::Key:0xb7b1e240 ... >
 puts key.name   #=> 'logs/today/2.log'
 key.exists?     #=> true

Return a public link to bucket.

 bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'

Store object data. The key is a String or Key instance. Returns true.

 bucket.put('logs/today/1.log', 'Olala!') #=> true

Rename object. Returns Aws::S3::Key instance.

 new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log')   #=> #<Aws::S3::Key:0xb7b1e240 ... >
 puts key.name   #=> 'logs/today/2.log'
 key.exists?     #=> true

Return bucket name as a String.

 bucket = Aws::S3.bucket('my_awesome_bucket')
 puts bucket #=> 'my_awesome_bucket'

[Validate]