This script looks for an EBS in the region “eu-west-1” with a tag whose key is “Application” and the value is passed as an argument, creating a snapshot of this EBS. In the same way, it searches for a snapshot by tag and deletes everything except the last one.

How to use it

Create a snapshot from EBS volume, which has the following tag:

  • Key: Application
  • Value: artem-test-app
python3 main.py create artem-test-app

Delete all versions of snapshots with the following tag except the latest:

  • Key: Application
  • Value: artem-test-app
python3 main.py cleanup artem-test-app

--

--

Example using AWS Cli only, without third-party utilities:

aws ecr describe-images \
--region eu-west-1 \
--repository-name artem-services \
--query "sort_by(imageDetails,& imagePushedAt)[ * ].imageTags[ * ]" \
--output text

Example using “jq” utility:

aws ecr describe-images \
--region eu-west-1 \
--repository-name artem-services \
| jq '.imageIds | map (.imageTag)|sort|.[]'

Where:

  • eu-west-1” — AWS region;
  • artem-services” — name of ECR repository

--

--