- Newest
- Most votes
- Most comments
Yes, you're right — in your current setup, if all 20 latest tagged images are older than 180 days, they will still be expired due to the sinceImagePushed > 180 days rule.
This happens because Amazon ECR lifecycle rules are evaluated in order of priority, and once a rule matches, it's applied immediately — even if a later rule would have preserved the image.
answered a year ago
Hello,
⚠ Issues in Your Current Policy:
Contradictory rules:
- rulePriority: 2 expires images if count > 20 — this is causing deletion of images even if they’re within 180 days.
- rulePriority: 3 tries to expire images older than 1800 days — seems like a typo (should be 180 days).
- tagStatus: any used in multiple rules – AWS only allows one rule with tagStatus: any in a lifecycle policy.
To retain the latest 20 images and all images pushed within the last 180 days in Amazon ECR, structure your lifecycle policy using the following rules:
{ "rules": [ { "rulePriority": 1, "description": "Expire untagged images older than 180 days", "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 180 }, "action": { "type": "expire" } }, { "rulePriority": 2, "description": "Expire tagged images older than 180 days", "selection": { "tagStatus": "tagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 180 }, "action": { "type": "expire" } }, { "rulePriority": 3, "description": "Retain the 20 most recent tagged images", "selection": { "tagStatus": "tagged", "countType": "imageCountMoreThan", "countNumber": 20 }, "action": { "type": "expire" } } ] }
This setup ensures:
- Images pushed in the last 180 days are preserved.
- At least 20 recent tagged images are kept, even if older than 180 days.
- Untagged images older than 180 days are expired.
Note: Amazon ECR allows only one rule with tagStatus: any, so separate rules for tagged and untagged are necessary.
For more information, refer to the official Amazon ECR Lifecycle Policy documentation.
answered a year ago
Relevant content
asked a year ago
asked 3 years ago
- AWS OFFICIALUpdated 3 years ago

But in this case if my all latest 20 images are older than 180 they will get deleted right