A process to delete old ECR images using the aws
CLI tool and jq
.
The general idea is to use aws ecr describe-images
to enumerate the images, and aws ecr batch-delete-image
to delete them. The latter command can take a --cli-input-json
argument specifying a JSON file which lists the images to delete. jq
is used to filter describe-images
to only the old ones, and munge it into the format that batch-delete-image
expects. Unfortunately, batch-delete-image
supports a maximum of 100 images at a time, so the process may need to be repeated several times.
Limitations:
- I can't find a way to do this as a neat command line pipeline.
--cli-input-json
seems to require that the input comes from a file, rather than STDIN. (AWS CLI tracking issue: aws/aws-cli#3209) - Since
batch-delete-image
can only handle 100 images at a time, thejq
command slices to[0:100]
after filtering to just the old images. This means the process may have to be re