Class: Aws::AutoScaling::Instance
- Inherits:
-
Object
- Object
- Aws::AutoScaling::Instance
- Defined in:
- gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#availability_zone ⇒ String
The Availability Zone for the instance.
-
#group_name ⇒ String
(also: #auto_scaling_group_name)
-
#health_status ⇒ String
The last reported health status of this instance.
-
#id ⇒ String
(also: #instance_id)
-
#image_id ⇒ String
The ID of the Amazon Machine Image (AMI) associated with the instance.
-
#instance_type ⇒ String
The instance type of the EC2 instance.
-
#launch_configuration_name ⇒ String
The launch configuration used to launch the instance.
-
#launch_template ⇒ Types::LaunchTemplateSpecification
The launch template for the instance.
-
#lifecycle_state ⇒ String
The lifecycle state for the instance.
-
#protected_from_scale_in ⇒ Boolean
Indicates whether the instance is protected from termination by Amazon EC2 Auto Scaling when scaling in.
-
#weighted_capacity ⇒ String
The number of capacity units contributed by the instance based on its instance type.
Actions collapse
-
#attach(options = {}) ⇒ EmptyStructure
-
#detach(options = {}) ⇒ Activity::Collection
-
#enter_standby(options = {}) ⇒ Activity::Collection
-
#exit_standby(options = {}) ⇒ Activity::Collection
-
#set_health(options = {}) ⇒ EmptyStructure
-
#terminate(options = {}) ⇒ Activity
Associations collapse
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::AutoScalingInstanceDetails
Returns the data for this Instance.
-
#data_loaded? ⇒ Boolean
Returns
trueif this resource is loaded. -
#initialize(*args) ⇒ Instance
constructor
A new instance of Instance.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::AutoScaling::Client] #wait_until instead
Constructor Details
#initialize(group_name, id, options = {}) ⇒ Instance #initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
24 25 26 27 28 29 30 31 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 24 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @group_name = extract_group_name(args, ) @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#attach(options = {}) ⇒ EmptyStructure
286 287 288 289 290 291 292 293 294 295 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 286 def attach( = {}) = Aws::Util.deep_merge(, auto_scaling_group_name: @group_name, instance_ids: [@id] ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_instances() end resp.data end |
#availability_zone ⇒ String
The Availability Zone for the instance.
55 56 57 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 55 def availability_zone data[:availability_zone] end |
#client ⇒ Client
146 147 148 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 146 def client @client end |
#data ⇒ Types::AutoScalingInstanceDetails
Returns the data for this Aws::AutoScaling::Instance. Calls
Client#describe_auto_scaling_instances if #data_loaded? is false.
168 169 170 171 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 168 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
176 177 178 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 176 def data_loaded? !!@data end |
#detach(options = {}) ⇒ Activity::Collection
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 307 def detach( = {}) batch = [] = Aws::Util.deep_merge(, auto_scaling_group_name: @group_name, instance_ids: [@id] ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_instances() end resp.data.activities.each do |a| batch << Activity.new( id: a.activity_id, data: a, client: @client ) end Activity::Collection.new([batch], size: batch.size) end |
#enter_standby(options = {}) ⇒ Activity::Collection
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 336 def enter_standby( = {}) batch = [] = Aws::Util.deep_merge(, auto_scaling_group_name: @group_name, instance_ids: [@id] ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.enter_standby() end resp.data.activities.each do |a| batch << Activity.new( id: a.activity_id, data: a, client: @client ) end Activity::Collection.new([batch], size: batch.size) end |
#exit_standby(options = {}) ⇒ Activity::Collection
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 360 def exit_standby( = {}) batch = [] = Aws::Util.deep_merge(, auto_scaling_group_name: @group_name, instance_ids: [@id] ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.exit_standby() end resp.data.activities.each do |a| batch << Activity.new( id: a.activity_id, data: a, client: @client ) end Activity::Collection.new([batch], size: batch.size) end |
#group ⇒ AutoScalingGroup
438 439 440 441 442 443 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 438 def group AutoScalingGroup.new( name: @group_name, client: @client ) end |
#group_name ⇒ String Also known as: auto_scaling_group_name
36 37 38 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 36 def group_name @group_name end |
#health_status ⇒ String
The last reported health status of this instance. Healthy means that
the instance is healthy and should remain in service. Unhealthy
means that the instance is unhealthy and Amazon EC2 Auto Scaling
should terminate and replace it.
88 89 90 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 88 def health_status data[:health_status] end |
#id ⇒ String Also known as: instance_id
42 43 44 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 42 def id @id end |
#image_id ⇒ String
The ID of the Amazon Machine Image (AMI) associated with the instance. This field shows the current AMI ID of the instance's root volume. It may differ from the original AMI used when the instance was first launched.
This field appears for:
Instances with root volume replacements through Instance Refresh
Instances launched with AMI overrides
This field won't appear for:
Existing instances launched from Launch Templates without overrides
Existing instances that didn’t have their root volume replaced through Instance Refresh
123 124 125 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 123 def image_id data[:image_id] end |
#instance_type ⇒ String
The instance type of the EC2 instance.
49 50 51 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 49 def instance_type data[:instance_type] end |
#launch_configuration ⇒ LaunchConfiguration?
446 447 448 449 450 451 452 453 454 455 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 446 def launch_configuration if data[:launch_configuration_name] LaunchConfiguration.new( name: data[:launch_configuration_name], client: @client ) else nil end end |
#launch_configuration_name ⇒ String
The launch configuration used to launch the instance. This value is not available if you attached the instance to the Auto Scaling group.
95 96 97 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 95 def launch_configuration_name data[:launch_configuration_name] end |
#launch_template ⇒ Types::LaunchTemplateSpecification
The launch template for the instance.
101 102 103 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 101 def launch_template data[:launch_template] end |
#lifecycle_state ⇒ String
The lifecycle state for the instance. The Quarantined state is not
used. For more information, see Amazon EC2 Auto Scaling instance
lifecycle in the Amazon EC2 Auto Scaling User Guide.
Valid values: Pending | Pending:Wait | Pending:Proceed |
Quarantined | InService | Terminating | Terminating:Wait |
Terminating:Proceed | Terminating:Retained | Terminated |
Detaching | Detached | EnteringStandby | Standby |
ReplacingRootVolume | ReplacingRootVolume:Wait |
ReplacingRootVolume:Proceed | RootVolumeReplaced |
Warmed:Pending | Warmed:Pending:Wait | Warmed:Pending:Proceed
| Warmed:Pending:Retained | Warmed:Terminating |
Warmed:Terminating:Wait | Warmed:Terminating:Proceed |
Warmed:Terminating:Retained | Warmed:Terminated |
Warmed:Stopped | Warmed:Running | Warmed:Hibernated
79 80 81 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 79 def lifecycle_state data[:lifecycle_state] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::AutoScaling::Instance.
Returns self making it possible to chain methods.
instance.reload.data
156 157 158 159 160 161 162 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 156 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_auto_scaling_instances(instance_ids: [@id]) end @data = resp.auto_scaling_instances[0] self end |
#protected_from_scale_in ⇒ Boolean
Indicates whether the instance is protected from termination by Amazon EC2 Auto Scaling when scaling in.
130 131 132 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 130 def protected_from_scale_in data[:protected_from_scale_in] end |
#set_health(options = {}) ⇒ EmptyStructure
405 406 407 408 409 410 411 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 405 def set_health( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.set_instance_health() end resp.data end |
#terminate(options = {}) ⇒ Activity
423 424 425 426 427 428 429 430 431 432 433 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 423 def terminate( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.terminate_instance_in_auto_scaling_group() end Activity.new( id: resp.data.activity.activity_id, data: resp.data.activity, client: @client ) end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::AutoScaling::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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 260 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 |
#weighted_capacity ⇒ String
The number of capacity units contributed by the instance based on its instance type.
Valid Range: Minimum value of 1. Maximum value of 999.
139 140 141 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 139 def weighted_capacity data[:weighted_capacity] end |