Class: AWS::AutoScaling::Instance
- Inherits:
-
Core::Resource
- Object
- Core::Resource
- AWS::AutoScaling::Instance
- Defined in:
- lib/aws/auto_scaling/instance.rb
Overview
A small wrapper around an EC2::Instance.
Getting Auto Scaling Instances
If you know the EC2 instance id, you can use AWS::AutoScaling::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.
Instance Attribute Summary collapse
-
#auto_scaling_group_name ⇒ String
readonly
The current value of auto_scaling_group_name.
-
#availability_zone_name ⇒ String
readonly
The current value of availability_zone_name.
-
#health_status ⇒ String
readonly
Returns the instance health status (e.g. ‘Healthly’ or ‘Unhealthly’).
-
#instance_id ⇒ String
(also: #id)
readonly
Instance_id Returns the EC2 id instance.
-
#launch_configuration_name ⇒ String
readonly
The current value of launch_configuration_name.
-
#lifecycle_state ⇒ String
readonly
The current value of lifecycle_state.
Instance Method Summary collapse
- #auto_scaling_group ⇒ AutoScaling::Group (also: #group)
- #availability_zone ⇒ EC2::AvailabilityZone
- #ec2_instance ⇒ EC2::Instance
-
#exists? ⇒ Boolean
Returns true if there exists an Auto Scaling instance with this instance id.
- #launch_configuration ⇒ LaunchConfiguration
- #set_health(status, options = {}) ⇒ nil
-
#terminate(decrement_desired_capacity) ⇒ Activity
(also: #delete)
Terminates the current Auto Scaling instance.
Instance Attribute Details
#auto_scaling_group_name ⇒ String (readonly)
Returns the current value of auto_scaling_group_name.
58 59 60 |
# File 'lib/aws/auto_scaling/instance.rb', line 58 def auto_scaling_group_name @auto_scaling_group_name end |
#availability_zone_name ⇒ String (readonly)
Returns the current value of availability_zone_name.
58 59 60 |
# File 'lib/aws/auto_scaling/instance.rb', line 58 def availability_zone_name @availability_zone_name end |
#health_status ⇒ String (readonly)
Returns the instance health status (e.g. ‘Healthly’ or ‘Unhealthly’).
58 59 60 |
# File 'lib/aws/auto_scaling/instance.rb', line 58 def health_status @health_status end |
#instance_id ⇒ String (readonly) Also known as: id
Returns instance_id Returns the EC2 id instance.
67 68 69 |
# File 'lib/aws/auto_scaling/instance.rb', line 67 def instance_id @instance_id end |
#launch_configuration_name ⇒ String (readonly)
Returns the current value of launch_configuration_name.
58 59 60 |
# File 'lib/aws/auto_scaling/instance.rb', line 58 def launch_configuration_name @launch_configuration_name end |
#lifecycle_state ⇒ String (readonly)
Returns the current value of lifecycle_state.
58 59 60 |
# File 'lib/aws/auto_scaling/instance.rb', line 58 def lifecycle_state @lifecycle_state end |
Instance Method Details
#auto_scaling_group ⇒ AutoScaling::Group Also known as: group
110 111 112 |
# File 'lib/aws/auto_scaling/instance.rb', line 110 def auto_scaling_group Group.new(auto_scaling_group_name, :config => config) end |
#availability_zone ⇒ EC2::AvailabilityZone
116 117 118 |
# File 'lib/aws/auto_scaling/instance.rb', line 116 def availability_zone EC2::AvailabilityZone.new(availability_zone_name, :config => config) end |
#ec2_instance ⇒ EC2::Instance
105 106 107 |
# File 'lib/aws/auto_scaling/instance.rb', line 105 def ec2_instance EC2::Instance.new(instance_id, :config => config) end |
#exists? ⇒ Boolean
Returns true if there exists an Auto Scaling instance with this instance id.
147 148 149 |
# File 'lib/aws/auto_scaling/instance.rb', line 147 def exists? !get_resource.auto_scaling_instances.empty? end |
#launch_configuration ⇒ LaunchConfiguration
121 122 123 |
# File 'lib/aws/auto_scaling/instance.rb', line 121 def launch_configuration LaunchConfiguration.new(launch_configuration_name, :config => config) end |
#set_health(status, options = {}) ⇒ nil
136 137 138 139 140 141 142 143 |
# File 'lib/aws/auto_scaling/instance.rb', line 136 def set_health status, = {} client_opts = {} client_opts[:instance_id] = instance_id client_opts[:health_status] = status client_opts[:should_respect_grace_period] = [:respect_grace_period] == true client.set_instance_health(client_opts) end |
#terminate(decrement_desired_capacity) ⇒ Activity Also known as: delete
Terminates the current Auto Scaling instance.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# 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 |