Skip to content

steffakasid/awsclean

Repository files navigation

AWSCLEAN - Cleanup unused and old AMIs on AWS

License Apache%202.0 blue link:https://github.com/steffakasid/awsclean/actions/workflows/codeql-analysis.yml link:https://github.com/steffakasid/awsclean/actions/workflows/release.yml link:https://github.com/steffakasid/awsclean/actions/workflows/go-test.yml

This tool is intended to:

  1. Get all available EC2 instances and get the used AMI

  2. Get all owned AMI’s

  3. Filter out AMI’s which are currently used bei EC2 instances

  4. 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 mockery to create the mocks:

To generate the mocks. Just run:
go generate ./...

The mockery configuration is done in:

.mockery.yaml
link:.mockery.yaml[role=include]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages