I want to set a lifecycle policy for my ECR. For all tagged images to have image count more than 1. It's currently set to Prefix and can't set it blank.
aws ecr policy console:
Thanks in advance.
Amazon ECR - Lifecycle Policy Rules 1 Amazon ECR lifecycle policies enable you to specify the lifecycle management of images in a repository. 2 A lifecycle policy is a set of one or more rules, where each rule defines an action for Amazon ECR. 3 The actions apply to images that contain tags prefixed with the given strings. ... More items...
For Rule description, type a description for the lifecycle policy rule. For Image status, choose Tagged, Untagged , or Any . If you specified Tagged for Image status, then for Tag prefixes, you can optionally specify a list of image tags on which to take action with your lifecycle policy.
A lifecycle policy contains one or more rules, where each rule defines an action for Amazon ECR. This provides a way to automate the cleaning up of unused images, for example expiring images based on age or count. You should expect that after creating a lifecycle policy, the affected images are expired within 24 hours.
In our ECR, we are having multiple repositories for each microservice. while building the code (for anyone service), creating an image out of it and pushing to ECR, we tag it with keyword - dev and build-XXX-XXX-XXX-XXX.
Lifecycle policies on all tagged images is now supported in ECR
You can use it by selecting Any
for "Image Status". Alternatively in JSON, you can create a rule with "tagStatus": "any"
:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
Unfortunately it doesn't seem to be possible at the moment. The only solution I see is to create an own policy for each of characters [a-zA-Z0-9] so that each of these policies match to tagged images prefixed with that letter. Like this:
Policy 1: when tagged and prefixed with "a", expire after 30 days
Policy 2: when tagged and prefixed with "b", expire after 30 days
Policy 3: when tagged and prefixed with "c", expire after 30 days
...
Quite insane approach, but it'd work.
To be able to use policy wisely, one should start using some known tag prefixes. For example, one could tag all test images with prefix test-
and release images with release-
. Then it'd be sufficient to create policies for just these two prefixes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With