AWS ECRのuntaggedを定期的に消す(シェルスクリプト)
定期的にuntaggedを消したい
jenkinsなどで、以下のコードを定期実行するだけ。
コードのrepository idはECRのコンソールから確認してコピってください。
echo start aws ecr get-login --no-include-email --region ap-northeast-1 --registry-ids !ここにrepository id! aws ecr describe-repositories --output text | awk '{print $5}' \ | while read rname; do echo $rname; aws ecr list-images --repository-name $rname --filter tagStatus=UNTAGGED --query 'imageIds[*]' --output text \ | while read imageId; do aws ecr batch-delete-image --repository-name $rname --image-ids imageDigest=$imageId; \ done; \ done echo done
ライフサイクルでもよかったけど、毎度人間が設定するとは思えなかったので、却下した。 docs.aws.amazon.com