I would like to know the CLI command to delete all images in an ECR repo.
Here is a bash script (delete.sh
) that you can delete any images from your ECR repository:
#!/bin/bash
aws ecr batch-delete-image --region $1 \
--repository-name $2 \
--image-ids "$(aws ecr list-images --region $1 --repository-name $2 --query 'imageIds[*]' --output json
)" || true
You can execute by a single command like this:
./delete.sh ap-southeast-1 my-ecr-repo
with the following values:
ap-southeast-1
is my AWS Regionmy-ecr-repo
is my ECR repo nameReferences: