GithubHelp home page GithubHelp logo

goodwinnk / aws-amicleaner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bonclay7/aws-amicleaner

0.0 2.0 0.0 113 KB

Cleanup your old unused ami and related snapshots

License: MIT License

Python 99.60% Dockerfile 0.40%

aws-amicleaner's Introduction

aws-amicleaner

Cleanup your old unused ami and related snapshots

Travis CI codecov.io pypi

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

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.

aws-amicleaner's People

Contributors

bonclay7 avatar erwinvaneyk avatar goodwinnk avatar pmg1991 avatar pyup-bot avatar rickhlx avatar stolendog avatar tedivm avatar unixorn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.