Listing all your AWS instances

Using boto I write a script to list all instances in all geographic regions.

The main motivation behind this is that in the amazon web console there is no a way (as far as I know) to list all the resouorces trespassing geographic regions.

Also added pretty table module to output data in a more redable way.

I’ve used the main tags that I use and the geographics where I have resource to organize perhaps you can use yours or none.

import boto.ec2
from prettytable import PrettyTable
regions = ["us-east-1", "us-west-2", "eu-west-1"]
table = PrettyTable()
table.field_names = ["region", "name", "id", "role", "state", "public-ip"]
for r in regions:
    conn=boto.ec2.connect_to_region(r)
    reservations = conn.get_all_instances()
    print ("Processing *****", r, "*****")
        for res in reservations:
            for inst in res.instances:
                if 'role' in inst.tags:
                    table.add_row([r, inst.tags['Name'], inst.tags['role'],, inst.id, inst.state, inst.ip_address])
                elif 'Name' in inst.tags:
                    table.add_row([r, inst.tags['Name'],"none", inst.id, inst.state, inst.ip_address])
                else:
                    table.add_row([r, "none", "none", inst.id, inst.state, inst.ip_address])
print(table)

 

Anuncios
Esta entrada fue publicada en Uncategorized. Guarda el enlace permanente.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s