class AWS::AutoScaling::Instance
A small wrapper around an {EC2::Instance}.
Getting Auto Scaling Instances¶ ↑
If you know the EC2
instance id, you can use {InstanceCollection#[]} to get the Auto Scaling instance.
instance = auto_scaling.instances['i-1234578'] instance.health_statue #=> :healthy instance.ec2_instance #=> <AWS::EC2::Instance instance_id:i-1234578>
Enumerating Auto Scaling Instances¶ ↑
You can enumerate ALL instances like so:
auto_scaling = AWS::AutoScaling.new auto_scaling.instances.each do |auto_scaling_instance| # ... end
If you want the instances for a single auto scaling group:
group = auto_scaling.groups['group-name'] group.auto_scaling_instances.each do |instance| # ... end
If you prefer {EC2::Instance} objects you should use {Group#ec2_instances} instead.
@attr_reader [String] auto_scaling_group_name
@attr_reader [String] launch_configuration_name
@attr_reader [String] health_status Returns the instance health status
(e.g. 'Healthly' or 'Unhealthly').
@attr_reader [String] availability_zone_name
@attr_reader [String] lifecycle_state
Attributes
@return [String] instance_id
Returns the EC2
id instance.
@return [String] instance_id
Returns the EC2
id instance.
Public Class Methods
@private
# File lib/aws/auto_scaling/instance.rb, line 61 def initialize instance_id, options = {} @instance_id = instance_id super end
Public Instance Methods
@return [AutoScaling::Group]
# File lib/aws/auto_scaling/instance.rb, line 110 def auto_scaling_group Group.new(auto_scaling_group_name, :config => config) end
@return [EC2::AvailabilityZone]
# File lib/aws/auto_scaling/instance.rb, line 116 def availability_zone EC2::AvailabilityZone.new(availability_zone_name, :config => config) end
@return [EC2::Instance]
# File lib/aws/auto_scaling/instance.rb, line 105 def ec2_instance EC2::Instance.new(instance_id, :config => config) end
@return [Boolean] Returns true if there exists an Auto Scaling
instance with this instance id.
# File lib/aws/auto_scaling/instance.rb, line 147 def exists? !get_resource.auto_scaling_instances.empty? end
@return [LaunchConfiguration]
# File lib/aws/auto_scaling/instance.rb, line 121 def launch_configuration LaunchConfiguration.new(launch_configuration_name, :config => config) end
@param [String] status Sets the health status of an instance.
Valid values inculde 'Healthy' and 'Unhealthy'
@param [Hash] options
@option options [Boolean] :respect_grace_period (false) If true,
this call should respect the grace period associated with this instance's Auto Scaling group.
@return [nil]
# File lib/aws/auto_scaling/instance.rb, line 136 def set_health status, options = {} client_opts = {} client_opts[:instance_id] = instance_id client_opts[:health_status] = status client_opts[:should_respect_grace_period] = options[:respect_grace_period] == true client.set_instance_health(client_opts) end
Terminates the current Auto Scaling instance.
@param [Boolean] decrement_desired_capacity Specifies whether or not
terminating this instance should also decrement the size of the AutoScalingGroup.
@return [Activity] Returns an activity that represents the
termination of the instance.
# File lib/aws/auto_scaling/instance.rb, line 160 def terminate decrement_desired_capacity client_opts = {} client_opts[:instance_id] = instance_id client_opts[:should_decrement_desired_capacity] = decrement_desired_capacity resp = client.terminate_instance_in_auto_scaling_group(client_opts) Activity.new_from( :terminate_instance_in_auto_scaling_group, resp.activity, resp.activity.activity_id, :config => config) end
Protected Instance Methods
# File lib/aws/auto_scaling/instance.rb, line 184 def get_resource attr_name = nil client_opts = {} client_opts[:instance_ids] = [instance_id] client.describe_auto_scaling_instances(client_opts) end
# File lib/aws/auto_scaling/instance.rb, line 180 def resource_identifiers [[:instance_id, instance_id]] end