Wednesday 14 June 2017

Stopping the ECS Task which are running on ec2 instances using bash script

#!/bin/bash $myecs_securitytoken=$(aws ecr get-authorization-token --region <region_name> --output text --query authorizationData[].authorizationToken) $myecs_securitytoken $aws ecs list-tasks --region <region_name> --cluster <cluster_name> --family <task_familyname> --query taskArns| cut -c46-81 > taskidinfo.out filename="taskidinfo.out" IFS=$'\n' for line in $(cat $filename) do $aws ecs stop-task --region <region_name> --cluster "<cluster_name>" --task $line --reason "stopping the task" done Note: Collect all the IDs of the task in the file taskidinfo.out, read each line from the file and stop the task using the taskID

No comments:

Post a Comment