Vasanth
Vasanth

Reputation: 11

AWS CLI, List ECR image which I specify with tags

Lets say "foo" is the repository name and I want to call the image which has two tags "boo, boo-0011"

This command displays all the images in the repository:

aws ecr describe-images --repository-name foo --query "sort_by(imageDetails,& imagePushedAt)[ * ].imageTags[ * ]"

From this how do I grep only the one which has a tag "boo"

Upvotes: 1

Views: 8670

Answers (3)

andrew lorien
andrew lorien

Reputation: 2688

Here is a pure jmespath query which will find the image which contains your tag. It filters all the images to find those with a tag containing your string, then selects the elements you need from those images.

--query 'imageDetails[?imageTags[?contains(@,`boo`)]].[imagePushedAt,imageDigest,imageTags]'

Warnings:

This will also select "boo-far" and "farboo".
If you want to use a variable for your search, change the quoting style:

--query "imageDetails[?imageTags[?contains(@,\`${tag}\`)]].[imagePushedAt,imageDigest,imageTags]"

Upvotes: 1

jarmod
jarmod

Reputation: 78793

You can use --filter tagStatus=xxx but that only allows you to filter on TAGGED or UNTAGGED images, not images with a specific tag.

To find images with a specific tag, say boo, you should be able to use the somewhat inscrutable, but very helpful, jq utility. For example:

aws ecr describe-images \
    --region us-east-1 \
    --repository-name foo \
    --filter tagStatus=TAGGED \
    | jq -c '.imageDetails[] | select( .imageTags[] | contains("boo") )'

Upvotes: 4

DatabaseShouter
DatabaseShouter

Reputation: 945

Personally I use grep for this

aws ecr describe-images --repository-name foo --query "sort_by(imageDetails,& imagePushedAt)[ * ].imageTags[ * ]" | grep -w 'boo'

-w is the grep command for the whole word matching.

Upvotes: 1

Related Questions