LoginSignup
14
9

More than 1 year has passed since last update.

aws cliでECSのリポジトリ内にどんなimageタグがbuildされているかワンライナーで答える

Last updated at Posted at 2016-12-14

時間の無い人向け

下記コマンドの<repositoryName>のところをご自身のECS(Amazon EC2 Container Service)に登録されたrepositoryNameに置き換えて実行します。

$ aws ecr list-images --repository-name <repositoryName> --query "imageIds[*].imageTag" --output table

--output tableと指定すると表形式で出力されます。

-------------------
|   ListImages    |
+-----------------+
|  hoge           |
|  fuga           |
|  moga           |
+-----------------+
$ aws ecr list-images --repository-name <repositoryName> --query "imageIds[*].imageTag" --output json

--output jsonとするとjson形式になります。

[
    "hoge",
    "fuga",
    "moga"
]

時間が無い人向けはここまで

リポジトリがたくさんある人向け

一旦、repository.listを作成します。

$ aws ecr describe-repositories --output json | jq -re ".repositories[].repositoryName"' > repository.list
$ cat repository.list
repository1
repository2
repository3
:

ECR内のリポジトリ名だけのテキストファイルが作成されるので、そのファイルをawkで拾っていきます。

for X in `awk '{print $1}' repository.list` ; do  echo $X ; aws ecr list-images --repository-name $X --query "imageIds[*].imageTag" --output table ; done
repository1
-------------------
|   ListImages    |
+-----------------+
|  hoge           |
|  fuga           |
|  moga           |
+-----------------+
repository2
-------------------
|   ListImages    |
+-----------------+
|  hoge-latest    |
|  fuga-latest    |
|  moga-latest    |
+-----------------+
repository3
-------------------
|   ListImages    |
+-----------------+
|  development    |
|  staging        |
|  production     |
+-----------------+
:
14
9
1

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
14
9