-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack-ips
executable file
·36 lines (30 loc) · 998 Bytes
/
stack-ips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import os
import sys
import argparse
import boto
from boto import ec2
import argparse
parser = argparse.ArgumentParser(description='Get IPs of instances created by a CloudFormation stack')
parser.add_argument('--public', action="store_true", default=False)
parser.add_argument('STACK_NAME', action="store")
args = parser.parse_args()
def get_region(obj):
for r in obj.regions():
if r.name == os.getenv('EC2_REGION'):
return r
ec2conn = boto.connect_ec2(region=get_region(ec2))
for res in ec2conn.get_all_instances():
for i in res.instances:
try:
if i.tags['aws:cloudformation:stack-name'] == args.STACK_NAME and i.state == 'running':
if args.public:
try:
print i.publicIp
except:
print i.public_dns_name
else:
print i.private_ip_address
except:
pass
sys.exit(0)