diff --git a/moto/ecs/exceptions.py b/moto/ecs/exceptions.py index 41f4f0eee..4f01ba258 100644 --- a/moto/ecs/exceptions.py +++ b/moto/ecs/exceptions.py @@ -16,7 +16,7 @@ class TaskDefinitionNotFoundException(JsonRESTError): def __init__(self): super().__init__( error_type="ClientException", - message="The specified task definition does not exist.", + message="Unable to describe task definition.", ) diff --git a/moto/ecs/models.py b/moto/ecs/models.py index 477066664..6ea027735 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -1414,12 +1414,15 @@ class EC2ContainerServiceBackend(BaseBackend): for task in tasks.keys(): if task.endswith(task_id): container_instance_arn = tasks[task].container_instance_arn - container_instance = self.container_instances[cluster.name][ - container_instance_arn.split("/")[-1] - ] - self.update_container_instance_resources( - container_instance, tasks[task].resource_requirements, removing=True - ) + if container_instance_arn: + container_instance = self.container_instances[cluster.name][ + container_instance_arn.split("/")[-1] + ] + self.update_container_instance_resources( + container_instance, + tasks[task].resource_requirements, + removing=True, + ) tasks[task].last_status = "STOPPED" tasks[task].desired_status = "STOPPED" tasks[task].stopped_reason = reason