Skip to content

Instantly share code, notes, and snippets.

@alexmojaki
Created July 8, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmojaki/8f7f96aa499424061ba26c519eba6a24 to your computer and use it in GitHub Desktop.
Save alexmojaki/8f7f96aa499424061ba26c519eba6a24 to your computer and use it in GitHub Desktop.
List all ECS task definitions not in use (i.e. not belonging to a task running in any cluster)
import re
import boto3
client = boto3.client('ecs', region_name='us-east-1')
used_tds = {re.match(r'arn:aws:ecs:us-east-1:667583086810:task-definition/([\w-]+):\d+$',
s['taskDefinition']
).group(1)
for c in client.list_clusters()['clusterArns']
for s in
client.describe_services(cluster=c, services=client.list_services(cluster=c)['serviceArns'])['services']
}
all_tds = set(client.list_task_definition_families()['families'])
for td in sorted(all_tds - used_tds):
print td
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment