EC2 instance listing using python boto3

#Purpose : To list all the AWS EC2 instances in the specified region.
#The script assume that you have a working aws cli configured with privilege to access the aws ec2 instances.
#!/usr/bin/env python
import boto3
import sys
import time
region_name = raw_input('Enter aws region for which you want to get the details of the EC2 Instance [sample : us-east-1]: ')
print (region_name, type(region_name))
time.sleep(5)
ec2 = boto3.resource('ec2', globals()['region_name'])
for instance in ec2.instances.all():
    print instance.id, instance.state, instance.private_ip_address, instance.public_ip_address, instance.tags

Comments

Popular posts from this blog

Logical volume vmxxxx_img is used by another device - Error on LVM removal

Open VZ cheat Sheet

Cheat sheet for Hardware RAID health check - Megaraid, Adaptec, 3wareraid and HPraid.