0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

条件を満たすECSタスクを探すスクリプト

Posted at

以下、条件を満たす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'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?