Created
July 8, 2016 09:46
-
-
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)
This file contains hidden or 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
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