Coder Social home page Coder Social logo

aws-python's Introduction

AWS SDK Python scripts

Some useful scripts to list or clean entire environments.

Table of Contents

  1. Requirements
  2. AWS Configuration
    1. Create an Access Key
    2. Configure credentials
      1. Guided configuration
      2. Manual configuration
  3. Running the scripts
    1. Delete VPCs resources
      1. Description
      2. Usage
      3. Examples
    2. List resources with their owner
      1. Description
      2. Usage
      3. Examples
    3. Delete Main AWS Services from Region
      1. Description
      2. Usage
      3. Examples

Requirements

These scripts depends on boto3 package, the AWS SDK for Python and require Python 2.6+. You can install boto3using yum

$ yum install python2-boto3

or using pip

$ pip install boto3

AWS configuration

Create an Access Key

To 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.

Configure credentials

You need to set up your AWS security credentials previously created to allow the API calls.

Guided configuration

You can use the AWS CLI to configure aws credentials. In that case you need to install the awscli with yum

$ yum install -y awscli

or pip

$ pip install awscli --upgrade --user

Now run aws configure and fill the fields ACCESS_KEY, SECRETand REGION.

$ aws configure

Your aws profile is ready.

Manual configuration

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-1

Your aws profile is ready.

Running the scripts

Delete VPCs resources

Beware! You need to provide AWS Access Key with high rights elevation.

Description

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)

Usage

$ ./delete_vpcs.py
+-----------------------------------+
|    Delete non default VPCs and    |
|       and its sub-resources       |
+-----------------------------------+

Examples

Show some help on usage

$ ./delete_vpcs.py -h

Run on Dry Run

$ ./delete_vpcs.py --check

Run on a specific region (parameter override profile)

$ ./delete_vpcs.py --region_name=eu-central-1

List resources with their owner

Description

Name: 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]

Usage

$ ./list_region_vpc.py
+-------------------------------------------+
|    List non default VPCs and Instances    |
|      for all regions with its owner.      |
+-------------------------------------------+

Examples

Show some help

$ ./list_region_vpc.py -h

Delete Main AWS Services from Region

Description

Name: 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)

Usage

$ ./reset_region.py
+-----------------------------------+
|       Delete all non default      |
|    resources and sub-resources    |
+-----------------------------------+

Examples

Show some help

$ ./reset_region.py -h

Run on Dry Run

$ ./reset_region.py --check

Run on a specific region (parameter override profile)

$ ./reset_region.py --region_name=eu-central-1

List Resource Groups resources

Description

Name: 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)

Usage

$ ./list_resource-groups.py
+----------------------------+
|    List Resource Groups    |
|         resources          |
+----------------------------+

Examples

Show some help

$ ./list_resource-groups.py -h

Run on Dry Run

$ ./list_resource-groups.py --check

Run on a specific region (parameter override profile)

$ ./list_resource-groups.py --region_name=eu-central-1

List Resource Groups resources

Description

Name: 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

Usage

$ ./control_resource-groups_instances.py
+----------------------------+
|    List Resource Groups    |
|         resources          |
+----------------------------+

Examples

Show some help

$ ./control_resource-groups_instances.py -h

Run on Dry Run

$ ./control_resource-groups_instances.py --check

Run on a specific region (parameter override profile)

$ ./control_resource-groups_instances.py --region_name=eu-central-1

Start all instances from all Resource Groups from the Region (region set in profile)

$ ./control_resource-groups_instances.py --start

Stop all instances included in Resource Group named myRessGroup

$ ./control_resource-groups_instances.py --group_name=myRessGroup --stop

aws-python's People

Contributors

germainlefebvre4 avatar

Watchers

 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.