ECS services: loop over ECS cluster and scale down all tasks to 0

Solution 1:

  1. List services:

    aws ecs list-services --cluster ${ecsClusterName}
    
  2. Write services in a file:

    aws ecs list-services --cluster ${ecsClusterName} | awk -F'"' '{print $2}' | rev | awk -F'/' '{print $1}' | rev | grep -v serviceArns > services.txt
    
  3. Scale to 0 services:

    for service in $(cat services.txt); do aws ecs update-service --cluster ${ecsClusterName} --service "$service" --desired-count 2 --no-cli-pager > /dev/null; done