#!/bin/bash function listRes() { aws --region $1 ecs list-clusters | jq -cr '.clusterArns[]' | parallel aws --region $1 ecs describe-clusters --clusters {} | jq -cr '.clusters[] | [.clusterName, .runningTasksCount, .capacityProviders[0]] | @csv' | tr -d \" } export -f listRes # Generate inventory of ec2 in all regions echo "ClusterName, TasksCount, CapacityProvider" aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do sem -j6 listRes $r done sem --wait