Overview

I had an opportunity to bulk delete Amazon ECR repositories, so here are my notes. Please exercise caution when running these commands.

Creating a List of Repositories

I referenced the following article.

https://qiita.com/fk_2000/items/bffd3b1ad6f3ab109766

Run the following command.

aws ecr describe-repositories --output json | jq -re ".repositories[].repositoryName" > repository.list

On macOS, if you don’t have the jq command, install it with brew install jq.

Deletion

Run the following command. The --force flag is used to delete even if images exist.

for X in `awk '{print $1}' repository.list` ; do aws ecr delete-repository --repository-name $X --force ; done

Summary

Please exercise sufficient caution when using these commands. I hope this serves as a helpful reference.