Created
July 22, 2019 18:05
-
-
Save jen20/e1c25426cc0a4a9b53cbb3560a3f02d1 to your computer and use it in GitHub Desktop.
Script to deregister all ECS Task Definitions in a given region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Worked like a charm, when deregistering task definitions from the console didn't play ball.
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
thanks for sharing, very helpful!