You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::AutoScaling::Instance

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

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes 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

    Parameters:

    • group_name (String)
    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Instance

    Options Hash (options):

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


21
22
23
24
25
26
27
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 21

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)
end

Instance Method Details

#attach(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.attach()

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:

  • (EmptyStructure)


125
126
127
128
129
130
131
132
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 125

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

#availability_zoneString

The Availability Zone for the instance.

Returns:

  • (String)


45
46
47
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 45

def availability_zone
  data.availability_zone
end

#clientClient

Returns:



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

def client
  @client
end

#dataTypes::AutoScalingInstanceDetails



106
107
108
109
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 106

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



114
115
116
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 114

def data_loaded?
  !!@data
end

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

Examples:

Request syntax with placeholder values


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

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    If True, the Auto Scaling group decrements the desired capacity value by the number of instances detached.

Returns:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 144

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

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    Specifies whether the instances moved to Standby mode count as part of the Auto Scaling group's desired capacity. If set, the desired capacity for the Auto Scaling group decrements by the number of instances moved to Standby mode.

Returns:



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 173

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

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 195

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

Returns:



262
263
264
265
266
267
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 262

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

#group_nameString Also known as: auto_scaling_group_name

Returns:

  • (String)


32
33
34
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 32

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 Auto Scaling should terminate and replace it.

Returns:

  • (String)


65
66
67
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 65

def health_status
  data.health_status
end

#idString Also known as: instance_id

Returns:

  • (String)


38
39
40
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 38

def id
  @id
end

#launch_configurationLaunchConfiguration?

Returns:



270
271
272
273
274
275
276
277
278
279
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 270

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.

Returns:

  • (String)


72
73
74
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 72

def launch_configuration_name
  data.launch_configuration_name
end

#lifecycle_stateString

The lifecycle state for the instance. For more information, see Auto Scaling Lifecycle in the Auto Scaling User Guide.

Returns:

  • (String)


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

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

Returns:

  • (self)


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

def load
  resp = @client.describe_auto_scaling_instances(instance_ids: [@id])
  @data = resp.auto_scaling_instances[0]
  self
end

#protected_from_scale_inBoolean

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

Returns:

  • (Boolean)


79
80
81
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 79

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,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :health_status (required, String)

    The health status of the instance. Set to Healthy if you want the instance to remain in service. Set to Unhealthy if you want the instance to be out of service. Auto Scaling will terminate and replace 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 will respect the grace period. Set this to False, if you do not want the call to respect the grace period associated with the group.

    For more information, see the description of the health check grace period for CreateAutoScalingGroup.

Returns:

  • (EmptyStructure)


233
234
235
236
237
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 233

def set_health(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.set_instance_health(options)
  resp.data
end

#terminate(options = {}) ⇒ Activity

Examples:

Request syntax with placeholder values


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

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :should_decrement_desired_capacity (required, Boolean)

    If true, terminating the instance also decrements the size of the Auto Scaling group.

Returns:



249
250
251
252
253
254
255
256
257
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/instance.rb', line 249

def terminate(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.terminate_instance_in_auto_scaling_group(options)
  Activity.new(
    id: resp.data.activity.activity_id,
    data: resp.data.activity,
    client: @client
  )
end