awsclean

command module
v1.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

= AWSCLEAN - Cleanup unused and old AMIs on AWS

image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[link="http://www.apache.org/licenses/LICENSE-2.0"]
image:https://github.com/steffakasid/awsclean/actions/workflows/codeql-analysis.yml/badge.svg[link:https://github.com/steffakasid/awsclean/actions/workflows/codeql-analysis.yml]
image:https://github.com/steffakasid/awsclean/actions/workflows/release.yml/badge.svg[link:https://github.com/steffakasid/awsclean/actions/workflows/release.yml]
image:https://github.com/steffakasid/awsclean/actions/workflows/go-test.yml/badge.svg[link:https://github.com/steffakasid/awsclean/actions/workflows/go-test.yml]

This tool is intended to:

. Get all available EC2 instances and get the used AMI
. Get all owned AMI's
. Filter out AMI's which are currently used bei EC2 instances
. Delete all AMI's which are older then the specified duration (default is 7 days)

== Usage

`awsclean [command] [flags]`

=== Preqrequisites

awsclean uses already provided credentials in ~/.aws/credentials also it uses the central configuration in ~/.aws/config!


=== Examples
`awsclean ami` scan all AMIs owned by self and delete them if they are unused and older then 7 days.             

`awsclean ami --account 2451251` scan all AMIs of self and were AWS account 2451251 are owner

`awsclean ami --dry-run` do not delete anything just show what you would do

`awsclean ami --older-then 5w` delete all images which are older then 5w and are unused

`awsclean ami --ignore ^amia.* --ignore ^amib.*` delete all images which name does not start with amia or amib

`awsclean ami --launch-templates` additionally scan launch templates for used AMIs

`awsclean ebs --older-then 5w` delete all EBS volumes which are older then 5w and are not bound

`awsclean ebs --dry-run` do not delete any EBS volume just show what you would do

=== Filter Logic

1st:: all used AMIs are filtered out
2nd:: all ignore patterns are matched an ignored AMIs are filtered out
3rd:: the age of the AMI is checked if it's younger then the given duration the AMI is filtered out

=== Flags
-a, --account string:: Set AWS account number to cleanup AMIs. Used to set owner information when selecting AMIs. If not set only 'self' is used.
-d, --dry-run:: If set to true nothing will be deleted. And amiclean will just show what it would do!
-o, --older-then string:: Set the duration string (e.g 5d, 1w etc.) how old AMIs must be to be deleted. E.g. if set to 7d, AMIs will be delete which are older then 7 days. (default "7d")
-i, --ignore stringArray:: Set ignore regex patterns. If a ami name matches the pattern it will be exclueded from cleanup.
-l, --launch-templates:: Additionally scan launch templates for used AMIs.
-?, --help:: Print usage information
-v, --version:: Print version information

== Development

=== Generate mock using mockery

In order to test the ec2client I used link:https://github.com/vektra/mockery[mockery] to create the mocks:

.To generate the mocks. Just run:
[source,sh]
----
go generate ./...
----

The mockery configuration is done in:

..mockery.yaml
[source, yaml]
----
include::.mockery.yaml[]
----

== TODO

* Publish Homebrew formula updates through one shared tap repository for all projects.

Documentation

Overview

Copyright © 2022 steffakasid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL