AWS CLI: ECR list-images, get newest

前端 未结 5 995
不思量自难忘°
不思量自难忘° 2020-12-31 04:48

Using AWS CLI, and jq if needed, I\'m trying to get the tag of the newest image in a particular repo.

Let\'s call the repo foo, and sa

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 05:33

    List latest 3 images

    aws ecr describe-images --repository-name gvh \
    --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[0]' --output yaml \
    | tail -n 3 | awk -F'- ' '{print $2}'
    

    Skip latest 3 images

    aws ecr describe-images --repository-name gvh \
    --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[0]' --output yaml \
    | head -n -3 | awk -F'- ' '{print $2}'
    

    Number '3' can be generalized in either head or tail command based on user requirement

提交回复
热议问题