Skip to content

Instantly share code, notes, and snippets.

@jen20
Created July 22, 2019 18:05
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jen20/e1c25426cc0a4a9b53cbb3560a3f02d1 to your computer and use it in GitHub Desktop.
Save jen20/e1c25426cc0a4a9b53cbb3560a3f02d1 to your computer and use it in GitHub Desktop.
Script to deregister all ECS Task Definitions in a given region
#!/usr/bin/env bash
get_task_definition_arns() {
aws ecs list-task-definitions --region ${AWS_REGION} \
| jq -M -r '.taskDefinitionArns | .[]'
}
delete_task_definition() {
local arn=$1
aws ecs deregister-task-definition \
--region us-east-2 \
--task-definition "${arn}" > /dev/null
}
if [ -z "${AWS_REGION}" ] ; then
(>&2 echo "AWS_REGION is not set")
exit 1
fi
for arn in $(get_task_definition_arns)
do
echo "Deregistering ${arn}..."
delete_task_definition "${arn}"
done
@anna-anisienia
Copy link

thanks for sharing, very helpful!

@klang
Copy link

klang commented Sep 16, 2020

Worked like a charm, when deregistering task definitions from the console didn't play ball.

@woutercouvaras
Copy link

A set of my aws keys got leaked and some lovely humans setup 342 clusters on ECS, across multiple regions. I used this script and created a couple more to deregister and delete the tasks, clusters and services, so a BIG thank you for sharing this!

To share the love, I've created a gist with the other two scripts scripts I wrote, very much inspired by this gist:

https://gist.github.com/woutercouvaras/a466afc9af65ff9d798b8401f19db6e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment