You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Aws::S3::Bucket
- Inherits:
-
Resources::Resource
- Object
- Resources::Resource
- Aws::S3::Bucket
- Defined in:
- aws-sdk-resources/lib/aws-sdk-resources/services/s3/bucket.rb
Instance Attribute Summary collapse
-
#creation_date ⇒ Time
readonly
Date the bucket was created.
-
#name ⇒ String
readonly
Attributes inherited from Resources::Resource
Instance Method Summary collapse
-
#acl ⇒ BucketAcl
-
#clear! ⇒ void
Deletes all objects and versioned objects from this bucket.
-
#cors ⇒ BucketCors
-
#create(options = {}) ⇒ Types::CreateBucketOutput
Creates a new S3 bucket.
-
#delete(options = {}) ⇒ Struct
Deletes the S3 bucket.
-
#delete!(options = { }) ⇒ void
Deletes all objects and versioned objects from this bucket and then deletes the bucket.
-
#delete_objects(options = {}) ⇒ Types::DeleteObjectsOutput
This operation enables you to delete multiple objects from a bucket using a single HTTP request.
-
#exists? ⇒ Boolean
Returns
true
if this Bucket exists. -
#initialize ⇒ Object
constructor
-
#lifecycle ⇒ BucketLifecycle
-
#lifecycle_configuration ⇒ BucketLifecycleConfiguration
-
#logging ⇒ BucketLogging
-
#multipart_uploads(options = {}) ⇒ Collection<MultipartUpload>
Returns a Collection of MultipartUpload resources.
-
#notification ⇒ BucketNotification
-
#object(key) ⇒ Object
-
#object_versions(options = {}) ⇒ Collection<ObjectVersion>
Returns a Collection of ObjectVersion resources.
-
#objects(options = {}) ⇒ Collection<ObjectSummary>
Returns a Collection of ObjectSummary resources.
-
#policy ⇒ BucketPolicy
-
#presigned_post(options = {}) ⇒ PresignedPost
Creates a PresignedPost that makes it easy to upload a file from a web browser direct to Amazon S3 using an HTML post form with a file field.
-
#put_object(options = {}) ⇒ Object
-
#request_payment ⇒ BucketRequestPayment
-
#tagging ⇒ BucketTagging
-
#url(options = {}) ⇒ String
Returns a public URL for this bucket.
-
#versioning ⇒ BucketVersioning
-
#wait_until_exists {|waiter| ... } ⇒ Bucket
Waits until this Bucket is exists.
-
#wait_until_not_exists {|waiter| ... } ⇒ Bucket
Waits until this Bucket is not_exists.
-
#website ⇒ BucketWebsite
Methods inherited from Resources::Resource
add_data_attribute, add_identifier, #data, data_attributes, #data_loaded?, identifiers, #wait_until
Methods included from Resources::OperationMethods
#add_batch_operation, #add_operation, #batch_operation, #batch_operation_names, #batch_operations, #operation, #operation_names, #operations
Instance Attribute Details
#creation_date ⇒ Time (readonly)
Date the bucket was created.
#name ⇒ String (readonly)
Instance Method Details
#acl ⇒ BucketAcl
#clear! ⇒ void
This method returns an undefined value.
Deletes all objects and versioned objects from this bucket
14 15 16 |
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/bucket.rb', line 14 def clear! object_versions.batch_delete! end |
#cors ⇒ BucketCors
#create(options = {}) ⇒ Types::CreateBucketOutput
Creates a new S3 bucket. To create a bucket, you must register with Amazon S3 and have a valid AWS Access Key ID to authenticate requests. Anonymous requests are never allowed to create buckets. By creating the bucket, you become the bucket owner.
Not every string is an acceptable bucket name. For information about bucket naming restrictions, see Working with Amazon S3 buckets.
If you want to create an Amazon S3 on Outposts bucket, see Create Bucket.
By default, the bucket is created in the US East (N. Virginia) Region. You can optionally specify a Region in the request body. You might choose a Region to optimize latency, minimize costs, or address regulatory requirements. For example, if you reside in Europe, you will probably find it advantageous to create buckets in the Europe (Ireland) Region. For more information, see Accessing a bucket.
If you send your create bucket request to the s3.amazonaws.com
endpoint, the request goes to the us-east-1 Region. Accordingly, the signature calculations in Signature Version 4 must use us-east-1 as the Region, even if the location constraint in the request specifies another Region where the bucket is to be created. If you create a bucket in a Region other than US East (N. Virginia), your application must be able to handle 307 redirect. For more information, see Virtual hosting of buckets.
When creating a bucket using this operation, you can optionally specify the accounts or groups that should be granted specific permissions on the bucket. There are two ways to grant the appropriate permissions using the request headers.
-
Specify a canned ACL using the
x-amz-acl
request header. Amazon S3 supports a set of predefined ACLs, known as canned ACLs. Each canned ACL has a predefined set of grantees and permissions. For more information, see Canned ACL. -
Specify access permissions explicitly using the
x-amz-grant-read
,x-amz-grant-write
,x-amz-grant-read-acp
,x-amz-grant-write-acp
, andx-amz-grant-full-control
headers. These headers map to the set of permissions Amazon S3 supports in an ACL. For more information, see Access control list (ACL) overview.You specify each grantee as a type=value pair, where the type is one of the following:
-
id
– if the value specified is the canonical user ID of an AWS account -
uri
– if you are granting permissions to a predefined group -
emailAddress
– if the value specified is the email address of an AWS accountUsing email addresses to specify a grantee is only supported in the following AWS Regions:
-
US East (N. Virginia)
-
US West (N. California)
-
US West (Oregon)
-
Asia Pacific (Singapore)
-
Asia Pacific (Sydney)
-
Asia Pacific (Tokyo)
-
Europe (Ireland)
-
South America (São Paulo)
For a list of all the Amazon S3 supported Regions and endpoints, see Regions and Endpoints in the AWS General Reference.
-
For example, the following
x-amz-grant-read
header grants the AWS accounts identified by account IDs permissions to read object data and its metadata:x-amz-grant-read: id="11112222333", id="444455556666"
-
You can use either a canned ACL or specify access permissions explicitly. You cannot do both.
The following operations are related to CreateBucket
:
#delete(options = {}) ⇒ Struct
Deletes the S3 bucket. All objects (including all object versions and delete markers) in the bucket must be deleted before the bucket itself can be deleted.
Related Resources
#delete!(options = { }) ⇒ void
This method returns an undefined value.
Deletes all objects and versioned objects from this bucket and then deletes the bucket.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/bucket.rb', line 34 def delete! = { } = { initial_wait: 1.3, max_attempts: 3, }.merge() attempts = 0 begin clear! delete rescue Errors::BucketNotEmpty attempts += 1 if attempts >= [:max_attempts] raise else Kernel.sleep([:initial_wait] ** attempts) retry end end end |
#delete_objects(options = {}) ⇒ Types::DeleteObjectsOutput
This operation enables you to delete multiple objects from a bucket using a single HTTP request. If you know the object keys that you want to delete, then this operation provides a suitable alternative to sending individual delete requests, reducing per-request overhead.
The request contains a list of up to 1000 keys that you want to delete. In the XML, you provide the object key names, and optionally, version IDs if you want to delete a specific version of the object from a versioning-enabled bucket. For each key, Amazon S3 performs a delete operation and returns the result of that delete, success, or failure, in the response. Note that if the object specified in the request is not found, Amazon S3 returns the result as deleted.
The operation supports two modes for the response: verbose and quiet. By default, the operation uses verbose mode in which the response includes the result of deletion of each key in your request. In quiet mode the response includes only keys where the delete operation encountered an error. For a successful deletion, the operation does not return any information about the delete in the response body.
When performing this operation on an MFA Delete enabled bucket, that attempts to delete any versioned objects, you must include an MFA token. If you do not provide one, the entire request will fail, even if there are non-versioned objects you are trying to delete. If you provide an invalid token, whether there are versioned keys in the request or not, the entire Multi-Object Delete request will fail. For information about MFA Delete, see MFA Delete.
Finally, the Content-MD5 header is required for all Multi-Object Delete requests. Amazon S3 uses the header value to ensure that your request body has not been altered in transit.
The following operations are related to DeleteObjects
:
#exists? ⇒ Boolean
Returns true
if this Bucket exists. Returns false
otherwise.
#lifecycle ⇒ BucketLifecycle
#lifecycle_configuration ⇒ BucketLifecycleConfiguration
#logging ⇒ BucketLogging
#multipart_uploads(options = {}) ⇒ Collection<MultipartUpload>
Returns a Collection of MultipartUpload resources. No API requests are made until you call an enumerable method on the collection. Client#list_multipart_uploads will be called multiple times until every MultipartUpload has been yielded.
#notification ⇒ BucketNotification
#object(key) ⇒ Object
#object_versions(options = {}) ⇒ Collection<ObjectVersion>
Returns a Collection of ObjectVersion resources. No API requests are made until you call an enumerable method on the collection. Client#list_object_versions will be called multiple times until every ObjectVersion has been yielded.
#objects(options = {}) ⇒ Collection<ObjectSummary>
Returns a Collection of ObjectSummary resources. No API requests are made until you call an enumerable method on the collection. Client#list_objects_v2 will be called multiple times until every ObjectSummary has been yielded.
#policy ⇒ BucketPolicy
#presigned_post(options = {}) ⇒ PresignedPost
You must specify :key
or :key_starts_with
. All other options
are optional.
Creates a PresignedPost that makes it easy to upload a file from a web browser direct to Amazon S3 using an HTML post form with a file field.
See the PresignedPost documentation for more information.
91 92 93 94 95 96 97 98 |
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/bucket.rb', line 91 def presigned_post( = {}) PresignedPost.new( client.config.credentials, client.config.region, name, {url: url}.merge() ) end |
#put_object(options = {}) ⇒ Object
#request_payment ⇒ BucketRequestPayment
#tagging ⇒ BucketTagging
#url(options = {}) ⇒ String
Returns a public URL for this bucket.
bucket = s3.bucket('bucket-name')
bucket.url
#=> "https://bucket-name.s3.amazonaws.com"
You can pass virtual_host: true
to use the bucket name as the
host name.
bucket = s3.bucket('my.bucket.com', virtual_host: true)
bucket.url
#=> "http://my.bucket.com"
73 74 75 76 77 78 79 |
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/bucket.rb', line 73 def url( = {}) if [:virtual_host] "http://#{name}" else s3_bucket_url end end |
#versioning ⇒ BucketVersioning
#wait_until_exists {|waiter| ... } ⇒ Bucket
Waits until this Bucket is exists. This method waits by polling Client#head_bucket until successful. An error is raised after a configurable number of failed checks.
This waiter uses the following defaults:
Configuration | Default |
---|---|
#delay |
5 |
#max_attempts |
20 |
You can modify defaults and register callbacks by passing a block argument.
#wait_until_not_exists {|waiter| ... } ⇒ Bucket
Waits until this Bucket is not_exists. This method waits by polling Client#head_bucket until successful. An error is raised after a configurable number of failed checks.
This waiter uses the following defaults:
Configuration | Default |
---|---|
#delay |
5 |
#max_attempts |
20 |
You can modify defaults and register callbacks by passing a block argument.