Skip to content

Commit 673a6cc

Browse files
committed
3 instances behind load balancer.
1 parent 3135a75 commit 673a6cc

1 file changed

Lines changed: 71 additions & 7 deletions

File tree

cloudformation.json

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
"Type": "String",
77
"Default": "t3.micro"
88
},
9-
"DesiredCapacity": {
10-
"Type": "Number",
11-
"Default": 2
12-
},
139
"ECSAMI": {
1410
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
1511
"Default": "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id"
@@ -52,6 +48,15 @@
5248
"MapPublicIpOnLaunch": true
5349
}
5450
},
51+
"PublicSubnet3": {
52+
"Type": "AWS::EC2::Subnet",
53+
"Properties": {
54+
"VpcId": { "Ref": "VPC" },
55+
"CidrBlock": "10.0.3.0/24",
56+
"AvailabilityZone": { "Fn::Select": [ 2, { "Fn::GetAZs": "" } ] },
57+
"MapPublicIpOnLaunch": true
58+
}
59+
},
5560
"PublicRouteTable": {
5661
"Type": "AWS::EC2::RouteTable",
5762
"Properties": {
@@ -81,6 +86,13 @@
8186
"RouteTableId": { "Ref": "PublicRouteTable" }
8287
}
8388
},
89+
"SubnetRouteTableAssociation3": {
90+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
91+
"Properties": {
92+
"SubnetId": { "Ref": "PublicSubnet3" },
93+
"RouteTableId": { "Ref": "PublicRouteTable" }
94+
}
95+
},
8496
"InstanceSecurityGroup": {
8597
"Type": "AWS::EC2::SecurityGroup",
8698
"Properties": {
@@ -102,6 +114,24 @@
102114
]
103115
}
104116
},
117+
"ALBSecurityGroup": {
118+
"Type": "AWS::EC2::SecurityGroup",
119+
"Properties": {
120+
"VpcId": { "Ref": "VPC" },
121+
"GroupDescription": "Allow inbound HTTP from anywhere",
122+
"SecurityGroupIngress": [
123+
{
124+
"IpProtocol": "tcp",
125+
"FromPort": 80,
126+
"ToPort": 80,
127+
"CidrIp": "0.0.0.0/0"
128+
}
129+
],
130+
"SecurityGroupEgress": [
131+
{ "IpProtocol": "-1", "CidrIp": "0.0.0.0/0" }
132+
]
133+
}
134+
},
105135
"InstanceRole": {
106136
"Type": "AWS::IAM::Role",
107137
"Properties": {
@@ -161,17 +191,51 @@
161191
}
162192
}
163193
},
194+
"ApplicationLoadBalancer": {
195+
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
196+
"Properties": {
197+
"Name": "ClusterALB",
198+
"Scheme": "internet-facing",
199+
"Subnets": [{ "Ref": "PublicSubnet1" }, { "Ref": "PublicSubnet2" }, { "Ref": "PublicSubnet3" }],
200+
"SecurityGroups": [{ "Ref": "ALBSecurityGroup" }]
201+
}
202+
},
203+
"ALBTargetGroup": {
204+
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
205+
"Properties": {
206+
"VpcId": { "Ref": "VPC" },
207+
"Port": 80,
208+
"Protocol": "HTTP",
209+
"TargetType": "instance",
210+
"HealthCheckPath": "/"
211+
}
212+
},
213+
"ALBListener": {
214+
"Type": "AWS::ElasticLoadBalancingV2::Listener",
215+
"Properties": {
216+
"LoadBalancerArn": { "Ref": "ApplicationLoadBalancer" },
217+
"Port": 80,
218+
"Protocol": "HTTP",
219+
"DefaultActions": [
220+
{
221+
"Type": "forward",
222+
"TargetGroupArn": { "Ref": "ALBTargetGroup" }
223+
}
224+
]
225+
}
226+
},
164227
"AutoScalingGroup": {
165228
"Type": "AWS::AutoScaling::AutoScalingGroup",
166229
"Properties": {
167-
"VPCZoneIdentifier": [ { "Ref": "PublicSubnet1" }, { "Ref": "PublicSubnet2" } ],
230+
"VPCZoneIdentifier": [ { "Ref": "PublicSubnet1" }, { "Ref": "PublicSubnet2" }, { "Ref": "PublicSubnet3" } ],
168231
"LaunchTemplate": {
169232
"LaunchTemplateId": { "Ref": "LaunchTemplate" },
170233
"Version": { "Fn::GetAtt": [ "LaunchTemplate", "LatestVersionNumber" ] }
171234
},
172-
"DesiredCapacity": { "Ref": "DesiredCapacity" },
235+
"DesiredCapacity": 3,
173236
"MinSize": "1",
174-
"MaxSize": "4"
237+
"MaxSize": "4",
238+
"TargetGroupARNs":[{ "Ref":"ALBTargetGroup" } ]
175239
}
176240
}
177241
}

0 commit comments

Comments
 (0)