title: Failed to delete ECS service in Cloudformation
body: <p>I'm running into a small issue deleting a Cloudformation stack that has an ECS cluster and ECS services as a part of it.</p>
  
  <p>If I just delete it manually from the CF console I get a failed delete with the following error:</p>
  
  <pre><code>AWS::ECS::Cluster The Cluster cannot be deleted while Container Instances are active or draining.
  </code></pre>
  
  <p>Following the AWS docs (<a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CleaningUp.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CleaningUp.html</a>) we wrote a script to delete the clusters using the AWS cli, this script has been working great for months until Friday.</p>
  
  <pre><code>stack=$1
  services="$(aws ecs list-services --cluster "$stack" | grep "$stack" | sed -e 's/"//g' -e 's/,//')"
  for service in $services; do
      aws ecs update-service --cluster "$stack" --service "$service" --desired-count 0
      aws ecs delete-service --cluster "$stack" --service "$service"
  done
  
  for id in $(aws ecs list-container-instances --cluster "$stack" | grep container-instance | sed -e 's/"//g' -e 's/,//'); do
      aws ecs deregister-container-instance --cluster "$stack" --container-instance "$id" --force
  done
  
  for service in $services; do
      aws ecs wait services-inactive --cluster "$stack" --services "$service"
  done
  
  aws ecs delete-cluster --cluster "$stack"
  aws cloudformation delete-stack --stack-name "$stack"
  </code></pre>
  
  <p>However we are now getting this new error:</p>
  
  <pre><code>AWS::ECS::Service: Service was not ACTIVE. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: xxxx-xxxx-xxxx-xxxx)
  </code></pre>
  
  <p>So I removed the ECS update and delete service calls thinking maybe they just need to be left ACTIVE and when we delete the ECS cluster it will take care of them. But when i do that i get this conflicting error:</p>
  
  <pre><code>AWS::ECS::Cluster The Cluster cannot be deleted while Services are active. (Service: AmazonECS; Status Code: 400; Error Code: ClusterContainsServicesException)
  </code></pre>
  
  <p>I assume I'm just doing something wrong, so any insight would be appreciated. </p>