-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalb.py
More file actions
46 lines (38 loc) · 1.37 KB
/
alb.py
File metadata and controls
46 lines (38 loc) · 1.37 KB
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
44
import troposphere.elasticloadbalancingv2 as elb
from troposphere import Ref, Template, Tags, Parameter
def create_load_balancer(template, public_subnet, public_subnet_2, security_group):
load_balancer = template.add_resource(elb.LoadBalancer(
"ApplicationElasticLoadBalancer",
Name="ApplicationELB",
Subnets=[Ref(public_subnet), Ref(public_subnet_2)],
Scheme="internet-facing",
SecurityGroups=[Ref(security_group)]
))
return load_balancer
def create_target_group(template, vpc, server_port):
target_group = template.add_resource(elb.TargetGroup(
"TargetGroupForELB",
VpcId=Ref(vpc),
HealthCheckIntervalSeconds="20",
HealthCheckProtocol="HTTP",
HealthCheckTimeoutSeconds="10",
HealthyThresholdCount="3",
Matcher=elb.Matcher(
HttpCode="200"),
Name="TargetGroup",
Port=Ref(server_port),
Protocol="HTTP",
UnhealthyThresholdCount="3"
))
return target_group
def create_elb_listener(template, load_balancer, target_group, server_port):
elb_listener = template.add_resource(elb.Listener(
"ELBListener",
LoadBalancerArn=Ref(load_balancer),
Port=Ref(server_port),
Protocol="HTTP",
DefaultActions=[elb.Action(
Type="forward",
TargetGroupArn=Ref(target_group)
)]
))