amazon-web-servicesaws-cliamazon-ecr

How to delete all images in an ECR repository?


I would like to know the CLI command to delete all images in an ECR repo.


Solution

  • 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:

    References: