forked from frommelmak/aws-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-elb.py
executable file
·36 lines (30 loc) · 1.54 KB
/
ec2-elb.py
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
# -*- coding: utf-8 -*-
import boto3
import sys
import argparse
def get_tag(ec2, id):
instance = ec2.Instance(id)
return instance.tags[0]['Value']
def list_elb(ec2):
client = boto3.client('elb')
response = client.describe_load_balancers()
for elb in range(len(response.get('LoadBalancerDescriptions'))):
load_balancer_name = response.get('LoadBalancerDescriptions')[elb].get('LoadBalancerName')
instance_state = client.describe_instance_health(LoadBalancerName=load_balancer_name)
print u"%s" % load_balancer_name
for instance in range(len(response.get('LoadBalancerDescriptions')[elb].get('Instances'))):
instance_id = instance_state.get('InstanceStates')[instance].get('InstanceId')
print u" └── %-20s (%s) Status: %s, Description: %s" % (
instance_id,
get_tag(ec2, instance_id),
instance_state.get('InstanceStates')[instance].get('State'),
instance_state.get('InstanceStates')[instance].get('Description')
)
def main():
parser = argparse.ArgumentParser(description='For every Elastic Load Balancer list the attached instances')
arg = parser.parse_args()
ec2 = boto3.resource('ec2')
list_elb(ec2)
if __name__ == '__main__':
sys.exit(main())