ECR multiple PolicyExecutionEvent executions at the same second.

0

We recently went to pull an image from ECR and it no longer existed.

Our ECR repositories have a simple Lifecycle policy:

{
  "rules": [
    {
      "rulePriority": 2,
      "description": "Expire untagged images",
      "selection": {
        "tagStatus": "untagged",
        "countType": "imageCountMoreThan",
        "countNumber": 5
      },
      "action": {
        "type": "expire"
      }
    },
    {
      "rulePriority": 6,
      "description": "Image Retention",
      "selection": {
        "tagStatus": "any",
        "countType": "imageCountMoreThan",
        "countNumber": 50
      },
      "action": {
        "type": "expire"
      }
    }
  ]
}

We found that for this repository, the PolicyExecutionEvent ran five times at the same time (EPOCH). And the result was that it run our rule 6 for those five times and the result was only 12 remaining tagged images.

A quick script found that we had a few other repositories with this multi-run issue:

#!/bin/bash
# find_ecr_lifecycle_events.sh

for repo in $( aws ecr describe-repositories --query "repositories[].repositoryName" | jq -r '.[]' |sort )
do
    echo $repo
    aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=PolicyExecutionEvent --lookup-attributes AttributeKey=ResourceName,AttributeValue=arn:aws:ecr:us-east-1:${ACCOUNTID}:repository/${repo} --max-items 50 | jq .Events[].EventTime  |sort |uniq -c |grep -v '^   1 ' | sed 's/^/    /'

done

Does anyone know why AWS sometimes runs this policy multiple times? Should we not be using an imageCoundMoreThan operator?

Thanks!

질문됨 2년 전88회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠