-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelb.py
executable file
·43 lines (27 loc) · 906 Bytes
/
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
37
38
39
40
41
42
43
#!/usr/bin/env python3
import boto3.session
import sys
elb_name = sys.argv[1]
region = sys.argv[2]
profile = sys.argv[3]
session = boto3.session.Session(profile_name=profile)
elb_new = session.client('elb',region_name=region)
response = elb_new.describe_instance_health(
LoadBalancerName=elb_name
)
def health_check(response):
InstanceStates = response.get('InstanceStates')
for i in InstanceStates:
if i.get('State') == 'OutOfService':
instances = i.get('InstanceId')
elb_new.deregister_instances_from_load_balancer(
LoadBalancerName=elb_name,
Instances=[
{'InstanceId' : instances},
]
)
print("Deregister Instance ID: {}".format(instances))
def main():
health_check(response)
if __name__ == '__main__':
main()