· 7 years ago · May 18, 2018, 12:44 AM
1#!/usr/bin/env python
2
3import boto
4import os
5
6ACCESS_KEY="<access key goes here>"
7SECRET_KEY="<secret key goes here>"
8
9ec2 = boto.connect_ec2(ACCESS_KEY, SECRET_KEY)
10s3 = boto.connect_s3(ACCESS_KEY, SECRET_KEY)
11
12images = ec2.get_all_images(owners='<AWS account numer>')
13print "Current Images:"
14for image in images:
15 print "\t%s (%s)" % (image.location, image.region)
16
17buckets = s3.get_all_buckets()
18print "\nCurrently used S3 Buckets:"
19for b in buckets:
20 print "\t%s" % (b.name)
21
22instances = ec2.get_all_instances()
23i = 0
24opts = {}
25print "\nCurrently running instances:"
26for r in instances:
27 for inst in r.instances:
28 opts[i] = (inst.id, inst.instance_type, inst.public_dns_name, inst.launch_time)
29 print "\t%d:" % i + " %s - %s : %s (Running since: %s)" % opts[i]
30 i += 1
31
32ssh = raw_input("\nChoose instance to connect to (or 'q' to quit): ")
33ssh != 'q' or exit(1)
34os.system("ssh -i ~/.ssh/<keyfile> root@" + opts[int(ssh)][2])