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

Represents a single S3 bucket.

@example Creating a Bucket

  bucket = s3.buckets.create('mybucket')

@example Getting an Existing Bucket

  bucket = s3.buckets['mybucket']

Methods

Included Modules

Model

Classes and Modules

Module AWS::S3::Bucket::ACLProxy
Module AWS::S3::Bucket::PolicyProxy

Attributes

name  [R]  @return [String] The bucket name

Public Class methods

@param [String] name @param [Hash] options @option options [String] :owner (nil) The owner id of this bucket.

Public Instance methods

@return [Boolean] Returns true if the two buckets have the same name.

Returns the bucket‘s access control list. This will be an instance of AccessControlList, plus an additional change method:

  bucket.acl.change do |acl|
    acl.grants.reject! do |g|
      g.grantee.canonical_user_id != bucket.owner.id
    end
  end

@return [AccessControlList]

Sets the bucket‘s access control list. acl can be:

  • An XML policy as a string (which is passed to S3 uninterpreted)
  • An AccessControlList object
  • Any object that responds to to_xml
  • Any Hash that is acceptable as an argument to AccessControlList#initialize.

@param [AccessControlList] acl @return [nil]

Returns a tree that allows you to expose the bucket contents like a directory structure.

@see Tree @param [Hash] options @option options [String] :prefix (nil) Set prefix to choose where

  the top of the tree will be.  A value of +nil+ means
  that the tree will include all objects in the collection.

@option options [String] :delimiter (’/’) The string that separates

  each level of the tree.  This is usually a directory separator.

@option options [Boolean] :append (true) If true, the delimiter is

  appended to the prefix when the prefix does not already end
  with the delimiter.

@return [Tree]

Deletes the current bucket.

@note the bucket must be empty. @return [nil]

Deletes any objects and versions which may be in the bucket, then deletes the bucket. @return [nil]

@return [Boolean] Returns true if the bucket has no objects

  (this includes versioned objects that are delete markers).

Enables versioning on this bucket. @return [nil]

@return [Boolean] Returns true if the two buckets have the same name

@note This method only indicates if there is a bucket in S3, not

  if you have permissions to work with the bucket or not.

@return [Boolean] Returns true if the bucket exists in S3.

@private

@return [String,nil] Returns the location constraint for a bucket

  (if it has one), nil otherwise.

@return [MultipartUploadCollection] Represents all of the

  multipart uploads that are in progress for this bucket.

@return [ObjectCollection] Represents all objects(keys) in

  this bucket.

@return [String] bucket owner id

Returns the bucket policy. This will be an instance of Policy. The returned policy will also have the methods of PolicyProxy mixed in, so you can use it to change the current policy or delete it, for example:

 if policy = bucket.policy
   # add a statement
   policy.change do |p|
     p.allow(...)
   end

   # delete the policy
   policy.delete
 end

Note that changing the policy is not an atomic operation; it fetches the current policy, yields it to the block, and then sets it again. Therefore, it‘s possible that you may overwrite a concurrent update to the policy using this method.

@return [Policy,nil] Returns the bucket policy (if it has one),

  or it returns +nil+ otherwise.

Sets the bucket‘s policy.

@param policy The new policy. This can be a string (which

  is assumed to contain a valid policy expressed in JSON), a
  Policy object or any object that responds to +to_json+.

@see Policy @return [nil]

Generates fields for a presigned POST to this object. All options are sent to the PresignedPost constructor.

@see PresignedPost

Suspends versioning on this bucket. @return [nil]

Returns the url for this bucket. @return [String] url to the bucket

versioned?()

Alias for versioning_enabled?

@return [Boolean] returns true if version is enabled on this bucket.

Returns the versioning status for this bucket. States include:

  • +:enabled+ - currently enabled
  • +:suspended+ - currently suspended
  • +:unversioned+ - versioning has never been enabled

@return [Symbol] the versioning state

@return [BucketVersionCollection] Represents all of the versioned

  objects stored in this bucket.

[Validate]