Skip to content

Instantly share code, notes, and snippets.

@eugenestarchenko
Forked from bpholt/deregister.sh
Created October 6, 2017 11:17
Show Gist options
  • Select an option

  • Save eugenestarchenko/d6cfe9d7933b0585b919c888c81275d4 to your computer and use it in GitHub Desktop.

Select an option

Save eugenestarchenko/d6cfe9d7933b0585b919c888c81275d4 to your computer and use it in GitHub Desktop.
Stop tasks on ECS Container Instance and Deregister it from ECS Cluster
#!/bin/bash
cluster=default
container_instance= # container instance guid
tasks=$(aws --region us-west-2 ecs list-tasks --container-instance $container_instance --cluster $cluster | jq -r '.taskArns | map(.[40:]) | reduce .[] as $item (""; . + $item + " ")')
for task in $tasks; do
aws --region us-west-2 ecs stop-task --task $task --cluster $cluster
done
aws --region us-west-2 ecs deregister-container-instance --cluster $cluster --container-instance $container_instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment