-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelb.py
More file actions
39 lines (28 loc) · 906 Bytes
/
Copy pathelb.py
File metadata and controls
39 lines (28 loc) · 906 Bytes
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
#!/usr/bin/env python
# Copyright (c) 2015 Nandini Taneja nandini.taneja@gmail.com
# All rights reserved.
import boto.ec2.elb
from boto.ec2.elb import HealthCheck
# get to my region in US East Coast
# AWS access and secret keys are in /etc/boto.cfg
regions = boto.ec2.regions()
myregion = regions[0]
conn = myregion.connect()
elb = boto.ec2.elb.connect_to_region(myregion)
#Create a ELB with port configuration and health checks
ports = [(80, 8080, 'http'), (443, 8443, 'tcp')]
hc = HealthCheck(
interval=20,
healthy_threshold=3,
unhealthy_threshold=5,
target='HTTP:8080/health'
)
lb = conn.create_load_balancer('nt-lb', zones, ports)
lb.configure_health_check(hc)
print "Load Balancer Created", lb.dns_name
#Add EC2 instabce to LB
reservations = conn.get_all_instances()
instance = reservation[0].instances
lb.register_instances(instance)
#remove instance
lb.deregister_instances(instance)