Class: Aws::AutoScaling::Instance

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Defined in:
lib/aws-sdk-autoscaling/instance.rb

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_name, id, options = {}) ⇒ Instance #initialize(options = {}) ⇒ Instance

Returns a new instance of Instance.

Overloads:

  • #initialize(group_name, id, options = {}) ⇒ Instance

    Options Hash (options):

  • #initialize(options = {}) ⇒ Instance

    Options Hash (options):

    • :group_name (required, String)
    • :id (required, String)
    • :client (Client)


24
25
26
27
28
29
30
31
# File 'lib/aws-sdk-autoscaling/instance.rb', line 24

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @group_name = extract_group_name(args, options)
  @id = extract_id(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
  @waiter_block_warned = false
end

Instance Method Details

#attach(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.attach()


283
284
285
286
287
288
289
290
291
292
# File 'lib/aws-sdk-autoscaling/instance.rb', line 283

def attach(options = {})
  options = Aws::Util.deep_merge(options,
    auto_scaling_group_name: @group_name,
    instance_ids: [@id]
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.attach_instances(options)
  end
  resp.data
end

#availability_zoneString

The Availability Zone for the instance.



55
56
57
# File 'lib/aws-sdk-autoscaling/instance.rb', line 55

def availability_zone
  data[:availability_zone]
end

#clientClient



143
144
145
# File 'lib/aws-sdk-autoscaling/instance.rb', line 143

def client
  @client
end

#dataTypes::AutoScalingInstanceDetails



165
166
167
168
# File 'lib/aws-sdk-autoscaling/instance.rb', line 165

def data
  load unless @data
  @data
end

#data_loaded?Boolean



173
174
175
# File 'lib/aws-sdk-autoscaling/instance.rb', line 173

def data_loaded?
  !!@data
end

#detach(options = {}) ⇒ Activity::Collection

Examples:

Request syntax with placeholder values


activity = instance.detach({
  should_decrement_desired_capacity: false, # required
})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    Indicates whether the Auto Scaling group decrements the desired capacity value by the number of instances detached.



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/aws-sdk-autoscaling/instance.rb', line 304

def detach(options = {})
  batch = []
  options = Aws::Util.deep_merge(options,
    auto_scaling_group_name: @group_name,
    instance_ids: [@id]
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.detach_instances(options)
  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

Examples:

Request syntax with placeholder values


activity = instance.enter_standby({
  should_decrement_desired_capacity: false, # required
})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    Indicates whether to decrement the desired capacity of the Auto Scaling group by the number of instances moved to ‘Standby` mode.



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/aws-sdk-autoscaling/instance.rb', line 333

def enter_standby(options = {})
  batch = []
  options = Aws::Util.deep_merge(options,
    auto_scaling_group_name: @group_name,
    instance_ids: [@id]
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.enter_standby(options)
  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

Examples:

Request syntax with placeholder values


instance.exit_standby()


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/aws-sdk-autoscaling/instance.rb', line 357

def exit_standby(options = {})
  batch = []
  options = Aws::Util.deep_merge(options,
    auto_scaling_group_name: @group_name,
    instance_ids: [@id]
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.exit_standby(options)
  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

#groupAutoScalingGroup



435
436
437
438
439
440
# File 'lib/aws-sdk-autoscaling/instance.rb', line 435

def group
  AutoScalingGroup.new(
    name: @group_name,
    client: @client
  )
end

#group_nameString Also known as: auto_scaling_group_name



36
37
38
# File 'lib/aws-sdk-autoscaling/instance.rb', line 36

def group_name
  @group_name
end

#health_statusString

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.



85
86
87
# File 'lib/aws-sdk-autoscaling/instance.rb', line 85

def health_status
  data[:health_status]
end

#idString Also known as: instance_id



42
43
44
# File 'lib/aws-sdk-autoscaling/instance.rb', line 42

def id
  @id
end

#identifiersObject

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.

Deprecated.


456
457
458
459
460
461
# File 'lib/aws-sdk-autoscaling/instance.rb', line 456

def identifiers
  {
    group_name: @group_name,
    id: @id
  }
end

#image_idString

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



120
121
122
# File 'lib/aws-sdk-autoscaling/instance.rb', line 120

def image_id
  data[:image_id]
end

#instance_typeString

The instance type of the EC2 instance.



49
50
51
# File 'lib/aws-sdk-autoscaling/instance.rb', line 49

def instance_type
  data[:instance_type]
end

#launch_configurationLaunchConfiguration?



443
444
445
446
447
448
449
450
451
452
# File 'lib/aws-sdk-autoscaling/instance.rb', line 443

def launch_configuration
  if data[:launch_configuration_name]
    LaunchConfiguration.new(
      name: data[:launch_configuration_name],
      client: @client
    )
  else
    nil
  end
end

#launch_configuration_nameString

The launch configuration used to launch the instance. This value is not available if you attached the instance to the Auto Scaling group.



92
93
94
# File 'lib/aws-sdk-autoscaling/instance.rb', line 92

def launch_configuration_name
  data[:launch_configuration_name]
end

#launch_templateTypes::LaunchTemplateSpecification

The launch template for the instance.



98
99
100
# File 'lib/aws-sdk-autoscaling/instance.rb', line 98

def launch_template
  data[:launch_template]
end

#lifecycle_stateString

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` | `Terminated` | `Detaching` | `Detached` | `EnteringStandby` | `Standby` | `Warmed:Pending` | `Warmed:Pending:Wait` | `Warmed:Pending:Proceed` | `Warmed:Terminating` | `Warmed:Terminating:Wait` | `Warmed:Terminating:Proceed` | `Warmed:Terminated` | `Warmed:Stopped` | `Warmed:Running`

[1]: docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-lifecycle.html



76
77
78
# File 'lib/aws-sdk-autoscaling/instance.rb', line 76

def lifecycle_state
  data[:lifecycle_state]
end

#loadself 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


153
154
155
156
157
158
159
# File 'lib/aws-sdk-autoscaling/instance.rb', line 153

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_inBoolean

Indicates whether the instance is protected from termination by Amazon EC2 Auto Scaling when scaling in.



127
128
129
# File 'lib/aws-sdk-autoscaling/instance.rb', line 127

def protected_from_scale_in
  data[:protected_from_scale_in]
end

#set_health(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.set_health({
  health_status: "XmlStringMaxLen32", # required
  should_respect_grace_period: false,
})

Options Hash (options):

  • :health_status (required, String)

    The health status of the instance. Set to ‘Healthy` to have the instance remain in service. Set to `Unhealthy` to have the instance be out of service. Amazon EC2 Auto Scaling terminates and replaces the unhealthy instance.

  • :should_respect_grace_period (Boolean)

    If the Auto Scaling group of the specified instance has a ‘HealthCheckGracePeriod` specified for the group, by default, this call respects the grace period. Set this to `False`, to have the call not respect the grace period associated with the group.

    For more information about the health check grace period, see [Set the health check grace period for an Auto Scaling group] in the *Amazon EC2 Auto Scaling User Guide*.

    [1]: docs.aws.amazon.com/autoscaling/ec2/userguide/health-check-grace-period.html



402
403
404
405
406
407
408
# File 'lib/aws-sdk-autoscaling/instance.rb', line 402

def set_health(options = {})
  options = options.merge(instance_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.set_instance_health(options)
  end
  resp.data
end

#terminate(options = {}) ⇒ Activity

Examples:

Request syntax with placeholder values


activity = instance.terminate({
  should_decrement_desired_capacity: false, # required
})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    Indicates whether terminating the instance also decrements the size of the Auto Scaling group.



420
421
422
423
424
425
426
427
428
429
430
# File 'lib/aws-sdk-autoscaling/instance.rb', line 420

def terminate(options = {})
  options = options.merge(instance_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.terminate_instance_in_auto_scaling_group(options)
  end
  Activity.new(
    id: resp.data.activity.activity_id,
    data: resp.data.activity,
    client: @client
  )
end

#wait_until(options = {}) {|resource| ... } ⇒ Resource

Deprecated.

Use [Aws::AutoScaling::Client] #wait_until instead

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 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(options) {|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

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Yield Parameters:

  • resource (Resource)

    to be used in the waiting condition.

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/aws-sdk-autoscaling/instance.rb', line 257

def wait_until(options = {}, &block)
  self_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(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    Aws::Waiters::Waiter.new(options).wait({})
  end
end

#weighted_capacityString

The number of capacity units contributed by the instance based on its instance type.

Valid Range: Minimum value of 1. Maximum value of 999.



136
137
138
# File 'lib/aws-sdk-autoscaling/instance.rb', line 136

def weighted_capacity
  data[:weighted_capacity]
end