class AWS::S3::Bucket


bucket = s3.buckets[‘mybucket’]

@example Getting an Existing Bucket
bucket = s3.buckets.create(‘mybucket’)
@example Creating a Bucket
Represents a single S3 bucket.

def ==(other)

Returns:
  • (Boolean) - Returns true if the two buckets have the same name.
def ==(other)
  other.kind_of?(Bucket) && other.name == name
end

def acl

Returns:
  • (AccessControlList) -
def acl
  acl = client.get_bucket_acl(:bucket_name => name).acl
  acl.extend ACLProxy
  acl.bucket = self
  acl
end

def acl=(acl)

Returns:
  • (nil) -

Parameters:
  • acl (AccessControlList) --
def acl=(acl)
  client.set_bucket_acl(:bucket_name => name, :acl => acl)
  nil
end

def as_tree options = {}

Returns:
  • (Tree) -

Options Hash: (**options)
  • :append (Boolean) -- If true, the delimiter is
  • :delimiter (String) -- The string that separates
  • :prefix (String) -- Set prefix to choose where

Parameters:
  • options (Hash) --

Other tags:
    See: Tree -
def as_tree options = {}
  objects.as_tree(options)
end

def delete

Returns:
  • (nil) -

Other tags:
    Note: - the bucket *must* be empty.
def delete
  client.delete_bucket(:bucket_name => @name)
  nil
end

def delete!

Returns:
  • (nil) -
def delete!
  versions.each{|version| version.delete }
  delete
end

def empty?

Returns:
  • (Boolean) - Returns true if the bucket has no objects
def empty?
  versions.first ? false : true
end

def enable_versioning

Returns:
  • (nil) -
def enable_versioning
  client.set_bucket_versioning(
    :bucket_name => @name,
    :state => :enabled)
  nil
end

def eql?(other_bucket)

Returns:
  • (Boolean) - Returns true if the two buckets have the same name
def eql?(other_bucket)
  self == other_bucket
end

def exists?

Returns:
  • (Boolean) - Returns true if the bucket exists in S3.

Other tags:
    Note: - This method only indicates if there is a bucket in S3, not
def exists?
  begin
    versioned? # makes a get bucket request without listing contents
               # raises a client error if the bucket doesn't exist or
               # if you don't have permission to get the bucket 
               # versioning status.
    true
  rescue Errors::NoSuchBucket => e
    false # bucket does not exist
  rescue Errors::ClientError => e
    true # bucket exists
  end
end

def initialize(name, options = {})

Options Hash: (**options)
  • :owner (String) -- The owner id of this bucket.

Parameters:
  • options (Hash) --
  • name (String) --
def initialize(name, options = {})
  # the S3 docs disagree with what the service allows,
  # so it's not safe to toss out invalid bucket names
  # S3::Client.validate_bucket_name!(name)
  @name = name
  @owner = options[:owner]
  super
end

def inspect

Other tags:
    Private: -
def inspect
  "#<AWS::S3::Bucket:#{name}>"
end

def location_constraint

Returns:
  • (String, nil) - Returns the location constraint for a bucket
def location_constraint
  client.get_bucket_location(:bucket_name => name).location_constraint
end

def multipart_uploads

Returns:
  • (MultipartUploadCollection) - Represents all of the
def multipart_uploads
  MultipartUploadCollection.new(self)
end

def objects

Returns:
  • (ObjectCollection) - Represents all objects(keys) in
def objects
  ObjectCollection.new(self)
end

def owner

Returns:
  • (String) - bucket owner id
def owner
  @owner || client.list_buckets.owner
end

def policy

Returns:
  • (Policy, nil) - Returns the bucket policy (if it has one),
def policy
  policy = client.get_bucket_policy(:bucket_name => name).policy
  policy.extend(PolicyProxy)
  policy.bucket = self
  policy
rescue Errors::NoSuchBucketPolicy => e
  nil
end

def policy=(policy)

Returns:
  • (nil) -

Other tags:
    See: Policy -

Parameters:
  • policy () -- The new policy. This can be a string (which
def policy=(policy)
  client.set_bucket_policy(:bucket_name => name, :policy => policy)
  nil
end

def presigned_post(options = {})

Other tags:
    See: PresignedPost -
def presigned_post(options = {})
  PresignedPost.new(self, options)
end

def suspend_versioning

Returns:
  • (nil) -
def suspend_versioning
  client.set_bucket_versioning(
    :bucket_name => @name,
    :state => :suspended)
  nil
end

def url

Returns:
  • (String) - url to the bucket
def url
  if client.dns_compatible_bucket_name?(name)
    "http://#{name}.s3.amazonaws.com/"
  else
    "http://s3.amazonaws.com/#{name}/"
  end
end

def versioning_enabled?

Returns:
  • (Boolean) - returns +true+ if version is enabled on this bucket.
def versioning_enabled?
  versioning_state == :enabled
end

def versioning_state

Returns:
  • (Symbol) - the versioning state
def versioning_state
  client.get_bucket_versioning(:bucket_name => @name).status
end

def versions

Returns:
  • (BucketVersionCollection) - Represents all of the versioned
def versions
  BucketVersionCollection.new(self)
end