ECS services: loop over ECS cluster and scale down all tasks to 0
Solution 1:
-
List services:
aws ecs list-services --cluster ${ecsClusterName}
-
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
-
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