以下、条件を満たすecsタスクを探す時に使用したshell script
#!/bin/bash
clusters=$(aws ecs list-clusters | jq -r '.clusterArns[]')
for cluster in ${clusters}; do
echo "====================="
echo "===cluster==="
echo $cluster
tasks=$(aws ecs list-tasks --cluster $cluster | jq -r '.taskArns[]')
echo "===tasks==="
if [ -n "$tasks" ]; then
echo $tasks
echo "===target==="
for task in ${tasks}; do
target=$(aws ecs describe-tasks --cluster $cluster --tasks $task --query 'tasks' | jq '.[] | select(.availabilityZone == "ap-northeast-1a")' | jq '.clusterArn')
if [ -n "$target" ]; then
echo $target
fi
done
else
echo "no task in $cluster"
fi
echo "====================="
done
以下部分をアレンジすれば条件に合ったecsタスクの情報を取得できます。
select(.availabilityZone == "ap-northeast-1a")' | jq '.clusterArn'