diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py
index 2be2415544df..ed6a48dd7ee5 100644
--- a/moto/autoscaling/models.py
+++ b/moto/autoscaling/models.py
@@ -7,6 +7,12 @@
DEFAULT_COOLDOWN = 300
+class InstanceState(object):
+ def __init__(self, instance, lifecycle_state="InService"):
+ self.instance = instance
+ self.lifecycle_state = lifecycle_state
+
+
class FakeScalingPolicy(object):
def __init__(self, name, adjustment_type, as_name, scaling_adjustment,
cooldown, autoscaling_backend):
@@ -125,7 +131,7 @@ def __init__(self, name, availability_zones, desired_capacity, max_size,
self.placement_group = placement_group
self.termination_policies = termination_policies
- self.instances = []
+ self.instance_states = []
self.set_desired_capacity(desired_capacity)
@classmethod
@@ -179,7 +185,7 @@ def set_desired_capacity(self, new_capacity):
else:
self.desired_capacity = new_capacity
- curr_instance_count = len(self.instances)
+ curr_instance_count = len(self.instance_states)
if self.desired_capacity == curr_instance_count:
return
@@ -195,14 +201,14 @@ def set_desired_capacity(self, new_capacity):
)
for instance in reservation.instances:
instance.autoscaling_group = self
- self.instances.extend(reservation.instances)
+ self.instance_states.append(InstanceState(instance))
else:
# Need to remove some instances
count_to_remove = curr_instance_count - self.desired_capacity
- instances_to_remove = self.instances[:count_to_remove]
- instance_ids_to_remove = [instance.id for instance in instances_to_remove]
+ instances_to_remove = self.instance_states[:count_to_remove]
+ instance_ids_to_remove = [instance.instance.id for instance in instances_to_remove]
self.autoscaling_backend.ec2_backend.terminate_instances(instance_ids_to_remove)
- self.instances = self.instances[count_to_remove:]
+ self.instance_states = self.instance_states[count_to_remove:]
class AutoScalingBackend(BaseBackend):
@@ -307,10 +313,10 @@ def delete_autoscaling_group(self, group_name):
self.autoscaling_groups.pop(group_name, None)
def describe_autoscaling_instances(self):
- instances = []
+ instance_states = []
for group in self.autoscaling_groups.values():
- instances.extend(group.instances)
- return instances
+ instance_states.extend(group.instance_states)
+ return instance_states
def set_desired_capacity(self, group_name, desired_capacity):
group = self.autoscaling_groups[group_name]
diff --git a/moto/autoscaling/responses.py b/moto/autoscaling/responses.py
index b9e62d7c3410..7d863c2db110 100644
--- a/moto/autoscaling/responses.py
+++ b/moto/autoscaling/responses.py
@@ -103,9 +103,9 @@ def set_desired_capacity(self):
return template.render()
def describe_auto_scaling_instances(self):
- instances = self.autoscaling_backend.describe_autoscaling_instances()
+ instance_states = self.autoscaling_backend.describe_autoscaling_instances()
template = self.response_template(DESCRIBE_AUTOSCALING_INSTANCES_TEMPLATE)
- return template.render(instances=instances)
+ return template.render(instance_states=instance_states)
def put_scaling_policy(self):
policy = self.autoscaling_backend.create_autoscaling_policy(
@@ -243,13 +243,13 @@ def execute_policy(self):
{{ group.launch_config_name }}
- {% for instance in group.instances %}
+ {% for instance_state in group.instance_states %}
HEALTHY
us-east-1e
- {{ instance.id }}
- {{ instance.autoscaling_group.launch_config_name }}
- InService
+ {{ instance_state.instance.id }}
+ {{ group.launch_config_name }}
+ {{ instance_state.lifecycle_state }}
{% endfor %}
@@ -315,14 +315,14 @@ def execute_policy(self):
DESCRIBE_AUTOSCALING_INSTANCES_TEMPLATE = """
- {% for instance in instances %}
+ {% for instance_state in instance_states %}
HEALTHY
- {{ instance.autoscaling_group.name }}
+ {{ instance_state.instance.autoscaling_group.name }}
us-east-1e
- {{ instance.id }}
- {{ instance.autoscaling_group.launch_config_name }}
- InService
+ {{ instance_state.instance.id }}
+ {{ instance_state.instance.autoscaling_group.launch_config_name }}
+ {{ instance_state.lifecycle_state }}
{% endfor %}