Used to decommission instances.
Testing in Python virtual environment using python version 3.6
python3.6 -m venv env source env/bin/activate pip install --upgrade awscli pip install --upgrade pip pip install --upgrade boto3
To ensure the code can easily be re-used I have set all the key elements as variables. These can also be defined as variables in any automation software.
Key | Value |
---|---|
dry_run | True or False - if yes the code will only check for access |
search_tag | Tag to search for instances, e.g. Name |
search_value | Value in search_tag to search for instances |
snap_prefix | Snapshot description |
arole | Role to assume across accounts |
accounts | list of accounts to process using above role e.g ['0000000000000','1111111111111','2222222222222222','333333333333333333'] |
- For each account listed
- Retrieve instance details from instances which fulfil the filter rules
- For each instance
- Shutdown if running
- Change EBS deleteontermination to True if False
- Snapshot EBS volume(s)
- Terminate Instance(s)
None
- Setup to use tags instead of input file
- Setup to use a role rather than AWS CLI credentials.
- Configure to use an array of accounts.
- remove the counts and instead use the cli wait commands (new post code writing)
- Rewrite in python
None presently
Dave Hart link to blog!