Prices are like fingernails. It’s a must to lower them continuously. When working with AWS, cleansing up unused sources is essential. In any other case, you’ll find yourself with a steadily rising AWS invoice and waste cash.
Do you construct AMIs robotically, for instance, with Packer? Discover ways to robotically clear up unused AMIs to scale back EBS storage consumption and prices.
A few 12 months in the past, the software we used to take away unused AMIs stopped working. As we couldn’t discover a working different, we began the undertaking aws-amicleaner.
How does the aws-amicleaner command line software work?
- Embrace AMIs by identify or tag.
- Exclude AMIs in use, youthful than N days, or the latest N photographs.
- Manually affirm the checklist of AMIs for deletion.
- Delete AMIs and linked EBS snapshots.
Examples
Requires Node.js >= 18.
The next instance exhibits the right way to delete all AMIs in eu-west-1
matching the next circumstances:
- Identify begins with
amiprefix-
- Older than 5 days
- Not in use by EC2 cases, ASGs, Launch Configurations, and Launch Templates.
Additionally, maintain the latest three photographs that match the circumstances.
npx aws-amicleaner --region eu-west-1 --include-name 'amiprefix-*' --exclude-newest 3 --exclude-days 5 --exclude-in-use --verbose |
The next itemizing exhibits a typical affirmation display.
+-----------+-------------+----------------------+--------------------------+---------+-----------------+-------------------------+ |
The next instance exhibits the right way to delete AMIs from all areas that begin with eu-west-*
, which resolves to eu-west-1
, eu-west-2
, and eu-west-3
these days. Additionally, the instance filters AMIs by tag key CostCenter
and tag worth X342-*1111
and the age of seven days. Apart from that the aws-amicleaner retains the latest 5 photographs matching these circumstances.
npx aws-amicleaner --region 'eu-west-*' --include-tag-key CostCenter --include-tag-value 'X342-*-1111' |
On the lookout for a technique to run the aws-amicleaner in an automatic method. Use the --force-delete
choice to skip the handbook approval. We use GitHub Actions to take away unused AMIs as soon as per 30 days.
npx aws-amicleaner --region 'eu-west-*' --include-tag-key CostCenter --include-tag-value 'X342-*-1111' --force-delete |
Arguments
Need extra? Here’s a checklist of all obtainable arguments supported by aws-amicleaner.
-h, |
Abstract
The aws-amicleaner is a small however helpfull software to delete unused AMIs and the corresponding EBS snapshots to scale back prices.
It’s easy to get began (requires Node.js >= 18).