Some useful scripts to list or clean entire environments.
Table of Contents
These scripts depends on boto3 package, the AWS SDK for Python and require Python 2.6+.
You can install boto3using yum
$ yum install python2-boto3or using pip
$ pip install boto3To use AWS API calls you need to make your account reachable with an Access Account.
See the Security Credentials page for more information on getting your keys. For more information on configuring boto3, check out the Quickstart section in the developer guide.
You need to set up your AWS security credentials previously created to allow the API calls.
You can use the AWS CLI to configure aws credentials. In that case you need to install the awscli with yum
$ yum install -y awsclior pip
$ pip install awscli --upgrade --userNow run aws configure and fill the fields ACCESS_KEY, SECRETand REGION.
$ aws configureYour aws profile is ready.
On Linux environments fill the configuration file at ~/.aws/credentials with your credentials previously made :
$ vi ~/.aws/credentials[default]
aws_access_key_id = <your access key id>
aws_secret_access_key = <your secret key>(optionnal) You can also fill the ~/.aws/config file to set your region on default profile
$ vi ~/.aws/config[default]
region = <your aws region> # e.g. region = eu-central-1Your aws profile is ready.
Beware! You need to provide AWS Access Key with high rights elevation.
Name: delete_vpcs.py
Description: Clear non-default resources on the region (from your profile or in parameter of the script).
Technical: This script mainly uses boto3.resource class to instanciate AWS entities.
Parameters:
--check: (none) Enable check mode and do not apply deletions--region_name <region>: (string) Name of the (only one) AWS Region (e.g. eu-west-1, eu-central-1)
$ ./delete_vpcs.py+-----------------------------------+
| Delete non default VPCs and |
| and its sub-resources |
+-----------------------------------+
Show some help on usage
$ ./delete_vpcs.py -hRun on Dry Run
$ ./delete_vpcs.py --checkRun on a specific region (parameter override profile)
$ ./delete_vpcs.py --region_name=eu-central-1Name: list_region_vpc.py
Description: List non-default VPCs and instances (for the moment) with their creator in order to trace who created it.
Technical: This script mainly uses boto3.resource class to instanciate AWS entities.
Parameters:
--check: (none) Enable check mode and do not apply any action [implemented but not used yet]
$ ./list_region_vpc.py+-------------------------------------------+
| List non default VPCs and Instances |
| for all regions with its owner. |
+-------------------------------------------+
Show some help
$ ./list_region_vpc.py -hName: reset_region.py
Description: Browse and delete main AWS Service non-default resources.
Technical: This script mainly uses boto3.client class to instanciate AWS entities.
Parameters:
--check: (none) Enable check mode and do not apply any action [implemented but not used yet]--region_name <region>: (string) Name of the (only one) AWS Region (e.g. eu-west-1, eu-central-1)
$ ./reset_region.py+-----------------------------------+
| Delete all non default |
| resources and sub-resources |
+-----------------------------------+
Show some help
$ ./reset_region.py -hRun on Dry Run
$ ./reset_region.py --checkRun on a specific region (parameter override profile)
$ ./reset_region.py --region_name=eu-central-1Name: list_resource-groups.py
Description: Browse Resource Groups and show resources linked.
Parameters:
--check: (none) Enable check mode and do not apply any action [implemented but not used yet]--region_name <region>: (string) Name of the (only one) AWS Region (e.g. eu-west-1, eu-central-1)
$ ./list_resource-groups.py+----------------------------+
| List Resource Groups |
| resources |
+----------------------------+
Show some help
$ ./list_resource-groups.py -hRun on Dry Run
$ ./list_resource-groups.py --checkRun on a specific region (parameter override profile)
$ ./list_resource-groups.py --region_name=eu-central-1Name: control_resource-groups_instances.py
Description: Browse Resource Groups and show resources linked.
Parameters:
--check: (none) Enable check mode and do not apply any action [implemented but not used yet]--region_name <Region>: (string) Name of the (only one) AWS Region (e.g. eu-west-1, eu-central-1)--group_name <Resource Group>: (string) Name of the Resource Group to control--start: (none) Start Resource Groups instances--stop: (none) Stop Resource Groups instances
$ ./control_resource-groups_instances.py+----------------------------+
| List Resource Groups |
| resources |
+----------------------------+
Show some help
$ ./control_resource-groups_instances.py -hRun on Dry Run
$ ./control_resource-groups_instances.py --checkRun on a specific region (parameter override profile)
$ ./control_resource-groups_instances.py --region_name=eu-central-1Start all instances from all Resource Groups from the Region (region set in profile)
$ ./control_resource-groups_instances.py --startStop all instances included in Resource Group named myRessGroup
$ ./control_resource-groups_instances.py --group_name=myRessGroup --stop