Class: Aws::S3::Bucket
- Inherits:
-
Object
- Object
- Aws::S3::Bucket
- Extended by:
- Deprecations
- Defined in:
- sig/bucket.rbs,
lib/aws-sdk-s3/customizations/bucket.rb,
sig/customizations/bucket.rbs,
lib/aws-sdk-s3/bucket.rb
Overview
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#bucket_arn ⇒ String
The Amazon Resource Name (ARN) of the S3 bucket.
-
#bucket_region ⇒ String
BucketRegionindicates the Amazon Web Services region where the bucket is located. -
#creation_date ⇒ Time
Date the bucket was created.
- #name ⇒ String
Actions collapse
- #create(options = {}) ⇒ Types::CreateBucketOutput
- #delete(options = {}) ⇒ EmptyStructure
- #delete_objects(options = {}) ⇒ Types::DeleteObjectsOutput
- #put_object(options = {}) ⇒ Object
Associations collapse
- #acl ⇒ BucketAcl
- #cors ⇒ BucketCors
- #identifiers ⇒ Object deprecated private Deprecated.
- #lifecycle ⇒ BucketLifecycle
- #lifecycle_configuration ⇒ BucketLifecycleConfiguration
- #logging ⇒ BucketLogging
- #multipart_uploads(options = {}) ⇒ MultipartUpload::Collection
- #notification ⇒ BucketNotification
- #object(key) ⇒ Object
- #object_versions(options = {}) ⇒ ObjectVersion::Collection
- #objects(options = {}) ⇒ ObjectSummary::Collection
- #policy ⇒ BucketPolicy
- #request_payment ⇒ BucketRequestPayment
- #tagging ⇒ BucketTagging
- #versioning ⇒ BucketVersioning
- #website ⇒ BucketWebsite
Instance Method Summary collapse
- #clear! ⇒ void
- #client ⇒ Client
-
#data ⇒ Types::Bucket
Returns the data for this Bucket.
-
#data_loaded? ⇒ Boolean
Returns
trueif this resource is loaded. - #delete!(options = {}) ⇒ Object
-
#exists?(options = {}) ⇒ Boolean
Returns
trueif the Bucket exists. -
#initialize(*args) ⇒ Bucket
constructor
A new instance of Bucket.
- #load ⇒ Object (also: #reload) private
- #presigned_post(options = {}) ⇒ Object
- #url(options = {}) ⇒ Object
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::S3::Client] #wait_until instead
- #wait_until_exists(options = {}, &block) ⇒ Bucket
- #wait_until_not_exists(options = {}, &block) ⇒ Bucket
Constructor Details
#initialize(name, options = {}) ⇒ Bucket #initialize(options = {}) ⇒ Bucket
Returns a new instance of Bucket.
13 14 15 |
# File 'sig/bucket.rbs', line 13
def initialize: (String name, Hash[Symbol, untyped] options) -> void
| (name: String, ?client: Client) -> void
| (Hash[Symbol, untyped] args) -> void
|
Instance Method Details
#bucket_arn ⇒ String
The Amazon Resource Name (ARN) of the S3 bucket. ARNs uniquely identify Amazon Web Services resources across all of Amazon Web Services.
27 |
# File 'sig/bucket.rbs', line 27
def bucket_arn: () -> ::String
|
#bucket_region ⇒ String
BucketRegion indicates the Amazon Web Services region where the
bucket is located. If the request contains at least one valid
parameter, it is included in the response.
24 |
# File 'sig/bucket.rbs', line 24
def bucket_region: () -> ::String
|
#clear! ⇒ void
This method returns an undefined value.
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Bucket.html#clear!-instance_method
15 16 17 |
# File 'lib/aws-sdk-s3/customizations/bucket.rb', line 15 def clear! object_versions.batch_delete! end |
#creation_date ⇒ Time
Date the bucket was created. This date can change when making changes to your bucket, such as editing its bucket policy.
21 |
# File 'sig/bucket.rbs', line 21
def creation_date: () -> ::Time
|
#data ⇒ Types::Bucket
Returns the data for this Aws::S3::Bucket.
33 |
# File 'sig/bucket.rbs', line 33
def data: () -> Types::Bucket
|
#data_loaded? ⇒ Boolean
36 |
# File 'sig/bucket.rbs', line 36
def data_loaded?: () -> bool
|
#delete(options = {}) ⇒ EmptyStructure
82 |
# File 'sig/bucket.rbs', line 82
def delete: (
|
#delete!(max_attempts:, initial_wait:) ⇒ void #delete!(arg0) ⇒ void
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aws-sdk-s3/customizations/bucket.rb', line 35 def delete!( = {}) = { initial_wait: 1.3, max_attempts: 3 }.merge() attempts = 0 begin clear! delete rescue Errors::BucketNotEmpty attempts += 1 raise if attempts >= [:max_attempts] Kernel.sleep([:initial_wait]**attempts) retry end end |
#delete_objects(options = {}) ⇒ Types::DeleteObjectsOutput
88 |
# File 'sig/bucket.rbs', line 88
def delete_objects: (
|
#exists?(options = {}) ⇒ Boolean
Returns true if the Bucket exists.
39 40 |
# File 'sig/bucket.rbs', line 39
def exists?: (?max_attempts: Integer, ?delay: Numeric, ?before_attempt: (^(Integer attempts) -> void), ?before_wait: (^(Integer attempts, untyped response) -> void)) -> bool
| (?Hash[Symbol, untyped]) -> bool
|
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1716 1717 1718 |
# File 'lib/aws-sdk-s3/bucket.rb', line 1716 def identifiers { name: @name } end |
#lifecycle ⇒ BucketLifecycle
166 |
# File 'sig/bucket.rbs', line 166
def lifecycle: () -> BucketLifecycle
|
#lifecycle_configuration ⇒ BucketLifecycleConfiguration
169 |
# File 'sig/bucket.rbs', line 169
def lifecycle_configuration: () -> BucketLifecycleConfiguration
|
#load ⇒ Object Also known as: reload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
136 137 138 139 140 141 142 143 |
# File 'lib/aws-sdk-s3/customizations/bucket.rb', line 136 def load @data = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do client.list_buckets.buckets.find { |b| b.name == name } end raise "unable to load bucket #{name}" if @data.nil? self end |
#multipart_uploads(options = {}) ⇒ MultipartUpload::Collection
175 |
# File 'sig/bucket.rbs', line 175
def multipart_uploads: (
|
#name ⇒ String
18 |
# File 'sig/bucket.rbs', line 18
def name: () -> String
|
#notification ⇒ BucketNotification
187 |
# File 'sig/bucket.rbs', line 187
def notification: () -> BucketNotification
|
#object_versions(options = {}) ⇒ ObjectVersion::Collection
193 |
# File 'sig/bucket.rbs', line 193
def object_versions: (
|
#objects(options = {}) ⇒ ObjectSummary::Collection
206 |
# File 'sig/bucket.rbs', line 206
def objects: (
|
#presigned_post(options = {}) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/aws-sdk-s3/customizations/bucket.rb', line 126 def presigned_post( = {}) PresignedPost.new( client.config.credentials, client.config.region, name, { url: url }.merge() ) end |
#request_payment ⇒ BucketRequestPayment
222 |
# File 'sig/bucket.rbs', line 222
def request_payment: () -> BucketRequestPayment
|
#url(virtual_host:, secure:) ⇒ String #url(arg0) ⇒ String
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/aws-sdk-s3/customizations/bucket.rb', line 88 def url( = {}) if [:virtual_host] scheme = .fetch(:secure, true) ? 'https' : 'http' "#{scheme}://#{name}" else # Taken from Aws::S3::Endpoints module unless client.config.regional_endpoint endpoint = client.config.endpoint.to_s end params = Aws::S3::EndpointParameters.new( bucket: name, region: client.config.region, use_fips: client.config.use_fips_endpoint, use_dual_stack: client.config.use_dualstack_endpoint, endpoint: endpoint, force_path_style: client.config.force_path_style, accelerate: client.config.use_accelerate_endpoint, use_global_endpoint: client.config.s3_us_east_1_regional_endpoint == 'legacy', use_object_lambda_endpoint: nil, disable_access_points: nil, disable_multi_region_access_points: client.config.s3_disable_multiregion_access_points, use_arn_region: client.config.s3_use_arn_region, ) endpoint = Aws::S3::EndpointProvider.new.resolve_endpoint(params) endpoint.url end end |
#versioning ⇒ BucketVersioning
228 |
# File 'sig/bucket.rbs', line 228
def versioning: () -> BucketVersioning
|
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::S3::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success or :failure from these callbacks,
it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/aws-sdk-s3/bucket.rb', line 231 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_exists(options = {}, &block) ⇒ Bucket
43 44 |
# File 'sig/bucket.rbs', line 43
def wait_until_exists: (?max_attempts: Integer, ?delay: Numeric, ?before_attempt: (^(Integer attempts) -> void), ?before_wait: (^(Integer attempts, untyped response) -> void)) ?{ (untyped waiter) -> void } -> Bucket
| (?Hash[Symbol, untyped]) ?{ (untyped waiter) -> void } -> Bucket
|
#wait_until_not_exists(options = {}, &block) ⇒ Bucket
47 48 |
# File 'sig/bucket.rbs', line 47
def wait_until_not_exists: (?max_attempts: Integer, ?delay: Numeric, ?before_attempt: (^(Integer attempts) -> void), ?before_wait: (^(Integer attempts, untyped response) -> void)) ?{ (untyped waiter) -> void } -> Bucket
| (?Hash[Symbol, untyped]) ?{ (untyped waiter) -> void } -> Bucket
|