简体   繁体   中英

Stop all ECS Cluster tasks with AWS CLI

Self answers:How to stop all tasks on a cluster with a single cli command, easily allowing for extra parameters to be passed.

The below will:

  1. Get all the tasks in the cluster
  2. Select the task arns using jq , -r removes the quotes from the json value.
  3. Pass each arn to the next command using xargs , the value is appended to the command (after --task). n-1 just ensures there is one command per arn, not sure if necessary.

aws ecs list-tasks --cluster "$ecs_cluster" | jq -r ".taskArns[]" | xargs -n1 aws ecs stop-task --no-cli-pager --cluster "$ecs_cluster" --task

--no-cli-pager prevents the output from stop-task from getting stuck after each execution.

Any optimization welcome. I saw another solution with awk but found it hard to use with passing extra params to the second command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM