Cleanup tool for AWS AMIs and snapshots
Project description
Cleanup your old unused ami and related snapshots
Description
This tool enables you 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. You can also check and delete EBS snapshots left orphaned by manual deletion of AMIs.
It can simply remove AMIs with a list of provided ids.
Prerequisites
python 2.7 or 3+
This tool assumes your AWS credentials are in your environment, 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
Minimum AWS IAM permissions
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",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeLaunchConfigurations"
],
"Resource": [
"*"
]
}
]
}
Installation
amicleaner is available on pypi and can be installed on your system with pip
From pypi
[sudo] pip install aws-amicleaner
From source
You can also clone or download from github the source and install with pip
cd aws-amicleaner/
pip install [--user] -e .
Usage
Getting help
amicleaner --help
Fetch and clean
Print report of groups and amis to be cleaned
amicleaner --full-report
Keep previous number of AMIs
amicleaner --full-report --keep-previous 10
Regroup by name or tags
amicleaner --mapping-key tags --mapping-values role env
Exclude amis based on tag values
amicleaner --mapping-key tags --mapping-values role env -excluded-mapping-values prod
Skip confirmation, can be useful for automation
amicleaner -f --keep-previous 2
Activate orphan snapshots checking
amicleaner --check-orphans
Delete a list of AMIs
amicleaner --from-ids ami-abcdef01 ami-abcdef02
See this blog article for more information.
History
0.1.0 (2016-08-22)
First release on PyPI.
0.1.1 (2016-08-22)
Documentation update
rst files in pip package
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file aws-amicleaner-0.2.2.tar.gz
.
File metadata
- Download URL: aws-amicleaner-0.2.2.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8a8721c055e59a20e56dd1796ff1228ae5c165341c104267c43e881e3cd8fdf |
|
MD5 | 7e607d54ab46215c1c642d8efffddd3d |
|
BLAKE2b-256 | 47c7b3f15132bf0220142612f9fe8bbdd1ad521f182394a7acc1cabcd3c1e2dc |
File details
Details for the file aws_amicleaner-0.2.2-py3.6.egg
.
File metadata
- Download URL: aws_amicleaner-0.2.2-py3.6.egg
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2dbec1ee7e299fda0e0c3ccf70cb9aacc0c58fd0a21926c86ac2a5756a91100 |
|
MD5 | cfbb8fe03b6039445570e2a1f8f7beee |
|
BLAKE2b-256 | 5bcf9358ed763d5c9a6f7440f36d50233f8a016aa087f47cc7fc376789b4c22a |
File details
Details for the file aws_amicleaner-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: aws_amicleaner-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e1d60d0c1dec7d24614aede6deff0a807531b29d348d1cf3f52361da69b2b70 |
|
MD5 | 07af7f8dce0ae74c000169b1424d316c |
|
BLAKE2b-256 | 2ec6e1bd0e2469b9c111a454244f532bc4e1ac76c844c8776e66f97bfe17481f |