You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Aws::Resources::ResourceAutoScaling::Activity, AutoScaling::AutoScalingGroup, AutoScaling::Instance, AutoScaling::LaunchConfiguration, AutoScaling::LifecycleHook, AutoScaling::LoadBalancer, AutoScaling::NotificationConfiguration, AutoScaling::Resource, AutoScaling::ScalingPolicy, AutoScaling::ScheduledAction, AutoScaling::Tag, CloudFormation::Event, CloudFormation::Resource, CloudFormation::Stack, CloudFormation::StackResource, CloudFormation::StackResourceSummary, CloudWatch::Alarm, CloudWatch::CompositeAlarm, CloudWatch::Metric, CloudWatch::Resource, DynamoDB::Resource, DynamoDB::Table, EC2::ClassicAddress, EC2::DhcpOptions, EC2::Image, EC2::Instance, EC2::InternetGateway, EC2::KeyPair, EC2::KeyPairInfo, EC2::NatGateway, EC2::NetworkAcl, EC2::NetworkInterface, EC2::NetworkInterfaceAssociation, EC2::PlacementGroup, EC2::Resource, EC2::Route, EC2::RouteTable, EC2::RouteTableAssociation, EC2::SecurityGroup, EC2::Snapshot, EC2::Subnet, EC2::Tag, EC2::Volume, EC2::Vpc, EC2::VpcAddress, EC2::VpcPeeringConnection, Glacier::Account, Glacier::Archive, Glacier::Job, Glacier::MultipartUpload, Glacier::Notification, Glacier::Resource, Glacier::Vault, IAM::AccessKey, IAM::AccessKeyPair, IAM::AccountPasswordPolicy, IAM::AccountSummary, IAM::AssumeRolePolicy, IAM::CurrentUser, IAM::Group, IAM::GroupPolicy, IAM::InstanceProfile, IAM::LoginProfile, IAM::MfaDevice, IAM::Policy, IAM::PolicyVersion, IAM::Resource, IAM::Role, IAM::RolePolicy, IAM::SamlProvider, IAM::ServerCertificate, IAM::SigningCertificate, IAM::User, IAM::UserPolicy, IAM::VirtualMfaDevice, OpsWorks::Layer, OpsWorks::Resource, OpsWorks::Stack, OpsWorks::StackSummary, Aws::RDS::AccountQuota, Aws::RDS::Certificate, Aws::RDS::DBCluster, Aws::RDS::DBClusterParameterGroup, Aws::RDS::DBClusterSnapshot, Aws::RDS::DBEngine, Aws::RDS::DBEngineVersion, Aws::RDS::DBInstance, Aws::RDS::DBLogFile, Aws::RDS::DBParameterGroup, Aws::RDS::DBParameterGroupFamily, Aws::RDS::DBSecurityGroup, Aws::RDS::DBSnapshot, Aws::RDS::DBSnapshotAttribute, Aws::RDS::DBSubnetGroup, Aws::RDS::Event, Aws::RDS::EventCategoryMap, Aws::RDS::EventSubscription, Aws::RDS::OptionGroup, Aws::RDS::OptionGroupOption, Aws::RDS::Parameter, Aws::RDS::PendingMaintenanceAction, Aws::RDS::ReservedDBInstance, Aws::RDS::ReservedDBInstancesOffering, Aws::RDS::Resource, Aws::RDS::ResourcePendingMaintenanceActionList, S3::Bucket, S3::BucketAcl, S3::BucketCors, S3::BucketLifecycle, S3::BucketLifecycleConfiguration, S3::BucketLogging, S3::BucketNotification, S3::BucketPolicy, S3::BucketRequestPayment, S3::BucketTagging, S3::BucketVersioning, S3::BucketWebsite, S3::MultipartUpload, S3::MultipartUploadPart, S3::Object, S3::ObjectAcl, S3::ObjectSummary, S3::ObjectVersion, S3::Resource, SNS::PlatformApplication, SNS::PlatformEndpoint, SNS::Resource, SNS::Subscription, SNS::Topic, SQS::Message, SQS::Queue, SQS::Resource
Class Attribute Summary collapseWhen constructing a resource, the client will default to an instance of the this class.
The resource name.
Marked private to prevent double documentation.
Marked private to prevent double documentation.
Registers a data attribute.
Returns an array of symbolized data attribute names.
Returns true
if #data has been loaded.
A new instance of Resource.
Loads data for this resource.
Waiter polls an API operation until a resource enters a desired state.
add_batch_operation, add_operation, batch_operation, batch_operation_names, batch_operations, operation, operation_names, operations
Constructor Details #initialize(*identifiers, options = {}) ⇒ ResourceReturns a new instance of Resource.
11 12 13 14 15 16
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 11 def initialize(*args) options = args.last.is_a?(Hash) ? args.pop.dup : {} @identifiers = (args, options) @data = options.delete(:data) @client = (options) endClass Attribute Details .client_class ⇒ Class<Client>?
Returns When constructing a resource, the client will default to an instance of the this class.
197 198 199
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 197 def client_class @client_class end.load_operation ⇒ Operations::LoadOperation?
200 201 202
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 200 def load_operation @load_operation end.resource_name ⇒ String?
Returns The resource name.
192 193 194
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 192 def resource_name @resource_name endInstance Attribute Details #client ⇒ Client
Marked private to prevent double documentation
20 21 22
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 20 def client @client end#identifiers ⇒ Hash<Symbol,String>
Marked private to prevent double documentation
24 25 26
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 24 def identifiers @identifiers endClass Method Details .add_data_attribute(name) ⇒ void
This method returns an undefined value.
Registers a data attribute. This defines a simple getter for the attribute which will access #data, loading the resource if necessary.
222 223 224 225
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 222 def add_data_attribute(name) safe_define_method(name) { data[name] } @data_attributes << name end.add_identifier(name) ⇒ void
This method returns an undefined value.
211 212 213 214 215
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 211 def add_identifier(name) name = name.to_sym safe_define_method(name) { @identifiers[name] } @identifiers << name end.data_attributes ⇒ Array<Symbol>
Returns an array of symbolized data attribute names.
229 230 231
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 229 def data_attributes @data_attributes.dup end.identifiers ⇒ Array<Symbol>
205 206 207
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 205 def identifiers @identifiers.dup endInstance Method Details #data ⇒ Struct
119 120 121 122
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 119 def data load unless @data @data end#data_loaded? ⇒ Boolean
Returns true
if #data has been loaded.
125 126 127
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 125 def data_loaded? !@data.nil? end#load ⇒ self Also known as: reload Note:
Calling this method will send a request to AWS.
Loads data for this resource.
145 146 147 148 149 150 151 152
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 145 def load if load_operation = self.class.load_operation @data = load_operation.call(resource:self, client:client) self else raise NotImplementedError, "#load not defined for #{self.class.name}" end end#wait_until(options = {}) {|resource| ... } ⇒ Resource Note:
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 UsageWaiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
resource.wait_until(options) {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }
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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 101 def wait_until(options = {}, &block) resource_copy = self.dup attempts = 0 options[:max_attempts] = 10 unless options.key?(:max_attempts) options[:delay] ||= 10 options[:poller] = Proc.new do attempts += 1 if block.call(resource_copy) [:success, resource_copy] else resource_copy.reload unless attempts == options[:max_attempts] :retry end end Waiters::Waiter.new(options).wait({}) end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4