-
-
Save murarisumit/15d7f8d8e22361e0e2d6 to your computer and use it in GitHub Desktop.
Get only running instance from a region and their IP Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from boto.ec2 import * | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("access_key", help = "AWS Access Key") | |
parser.add_argument("secret_key", help = "AWS Secret Key") | |
parser.add_argument("--region", help = "AWS Region", default = "us-east-1") | |
parser.add_argument("--all", help = "show not just running instances", action = "store_true") | |
args = parser.parse_args() | |
conn = connect_to_region(args.region, aws_access_key_id = args.access_key, aws_secret_access_key = args.secret_key) | |
instances = conn.get_only_instances() | |
filters = { } | |
if not args.all: | |
filters = { | |
'instance-state-name' : 'running' | |
} | |
instances = conn.get_only_instances(filters = filters) | |
for instance in instances: | |
print instance.ip_address + " " + instance.tags['Name'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment