import boto3 client = boto3.client('ecs') def get_clusters(): clusters = [] response = client.list_clusters() clusters.extend(response['clusterArns']) while 'nextToken' in response: response = client.list_clusters(nextToken=response['nextToken']) clusters.extend(response['clusterArns']) return clusters def get_services(clusters): i = 0 services = [] while i < len(clusters): response = client.list_services(cluster=clusters[i]) services.extend(response['serviceArns']) i += 1 return services def get_services_with_app_family_tag(services): contains_app_family = [] j = 0 while j < len(services): response = client.list_tags_for_resource( resourceArn=services[j] ) tags = response['tags'] i = 0 while i < len(tags): if 'application_family' in tags[i].values(): contains_app_family.append({'service_arn': services[j]}) i += 1 j += 1 return contains_app_family def print_percentage_info(contains_app_family, services): percent = (len(contains_app_family) / len(services)) * 100 print('Amount of services: ' + str(len(services))) print('Contains app family tag: ' + str(len(contains_app_family))) print('Percent ' + str(int(percent)) + '%') def main(): """Start script.""" ecs_clusters = get_clusters() ecs_services = get_services(ecs_clusters) services_with_app_family_tag = get_services_with_app_family_tag(ecs_services) print_percentage_info(services_with_app_family_tag,ecs_services) if __name__ == '__main__': main()