Cleanup tool for AWS AMIs and snapshots
Project description
Cleanup your old unused ami and related snapshots
Description
This tools permits to clean your custom Amazon Machine Images (AMI) and related EBS Snapshots.
You can either run in fetch and clean mode where the tool will retrieve all your private AMIs and EC2 instances, exclude AMIs being holded by your EC2 instances (it can be useful if you use autoscaling, and so on …). It applies a filter based on their names or tags and a number of previous AMIs you want to keep.
It can simply remove AMIs with a list of provided ids !
Prerequisites
This tool assumes your AWS credentials sourced, either with aws credentials variables :
export AWS_DEFAULT_REGION='your region'
export AWS_ACCESS_KEY_ID='with token Access ID'
export AWS_SECRET_ACCESS_KEY='with token AWS Secret'
or with awscli :
export AWS_PROFILE=profile-name
How does it work ?
To run the script properly, your aws user must have at least these permissions in iam:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1458638250000",
"Effect": "Allow",
"Action": [
"ec2:DeleteSnapshot",
"ec2:DeregisterImage",
"ec2:DescribeImages",
"ec2:DescribeInstances",
"ec2:DescribeSnapshots"
],
"Resource": [
"arn:aws:ec2:::*"
]
}
]
}
Getting help
amicleaner/cli.py --help
Clean a list of AMIs
amicleaner/cli.py --from-ids ami-abcdef01 ami-abcdef02
Fetch and clean
Print report of groups and amis to be cleaned
amicleaner/cli.py --full-report
Keep previous number of AMIs
amicleaner/cli.py --full-report --keep-previous 10
Regroup by name or tags
amicleaner/cli.py --mapping-key tags --mapping-values role env
Skip confirmation, can be useful for automation
amicleaner/cli.py -f --keep-previous 2
Using virtual env
$ virtualenv env
$ . env/bin/activate
(env) aws-amicleaner $ pip install -r requirements.txt
(env) aws-amicleaner $ amicleaner/cli.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.