ECR lifecycle policy 전체 repository 적용

2023. 6. 28. 15:22기타/scripts

728x90
SMALL

- 개요

ECR Repository를 생성하면 기본적으로 LifeCycle이 적용되지 않으며, 해당 메뉴까지 나눠져 있어서 그냥 데이터가 계속 쌓이면서 과금이 된다. 아래는 계정의 전체 ECR에 untagged image 15개 이상 부터 삭제하라는 LifeCycle을 일괄 적용하는 스크립트이다.  

 

 

- 스크립트 ( ecr_retention_put.sh )

#!/bin/bash
for i in $(aws ecr describe-repositories --query 'repositories[*].repositoryName[]' --output text)
do
        aws ecr put-lifecycle-policy --repository-name $i --lifecycle-policy-text "file://policy.json"
done

 

 

- policy.json

{
   "rules": [
       {
           "rulePriority": 1,
           "description": "remove",
           "selection": {
               "tagStatus": "untagged",
               "countType": "imageCountMoreThan",
               "countNumber": 15
           },
           "action": {
               "type": "expire"
           }
       }
   ]
}

 

728x90
LIST

'기타 > scripts' 카테고리의 다른 글

ip address location 확인하는 방법  (0) 2023.06.09
tg_attr_deg_delay.sh  (0) 2022.12.07
elb_attr_delete_protection.sh  (0) 2022.12.07
retention 없는 CloudWatch logs의 log groups  (0) 2022.12.07
codepipeline stage status  (0) 2022.11.21