|
6 | 6 | "Type": "String", |
7 | 7 | "Default": "t3.micro" |
8 | 8 | }, |
9 | | - "DesiredCapacity": { |
10 | | - "Type": "Number", |
11 | | - "Default": 2 |
12 | | - }, |
13 | 9 | "ECSAMI": { |
14 | 10 | "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", |
15 | 11 | "Default": "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id" |
|
52 | 48 | "MapPublicIpOnLaunch": true |
53 | 49 | } |
54 | 50 | }, |
| 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 | + }, |
55 | 60 | "PublicRouteTable": { |
56 | 61 | "Type": "AWS::EC2::RouteTable", |
57 | 62 | "Properties": { |
|
81 | 86 | "RouteTableId": { "Ref": "PublicRouteTable" } |
82 | 87 | } |
83 | 88 | }, |
| 89 | + "SubnetRouteTableAssociation3": { |
| 90 | + "Type": "AWS::EC2::SubnetRouteTableAssociation", |
| 91 | + "Properties": { |
| 92 | + "SubnetId": { "Ref": "PublicSubnet3" }, |
| 93 | + "RouteTableId": { "Ref": "PublicRouteTable" } |
| 94 | + } |
| 95 | + }, |
84 | 96 | "InstanceSecurityGroup": { |
85 | 97 | "Type": "AWS::EC2::SecurityGroup", |
86 | 98 | "Properties": { |
|
102 | 114 | ] |
103 | 115 | } |
104 | 116 | }, |
| 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 | + }, |
105 | 135 | "InstanceRole": { |
106 | 136 | "Type": "AWS::IAM::Role", |
107 | 137 | "Properties": { |
|
161 | 191 | } |
162 | 192 | } |
163 | 193 | }, |
| 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 | + }, |
164 | 227 | "AutoScalingGroup": { |
165 | 228 | "Type": "AWS::AutoScaling::AutoScalingGroup", |
166 | 229 | "Properties": { |
167 | | - "VPCZoneIdentifier": [ { "Ref": "PublicSubnet1" }, { "Ref": "PublicSubnet2" } ], |
| 230 | + "VPCZoneIdentifier": [ { "Ref": "PublicSubnet1" }, { "Ref": "PublicSubnet2" }, { "Ref": "PublicSubnet3" } ], |
168 | 231 | "LaunchTemplate": { |
169 | 232 | "LaunchTemplateId": { "Ref": "LaunchTemplate" }, |
170 | 233 | "Version": { "Fn::GetAtt": [ "LaunchTemplate", "LatestVersionNumber" ] } |
171 | 234 | }, |
172 | | - "DesiredCapacity": { "Ref": "DesiredCapacity" }, |
| 235 | + "DesiredCapacity": 3, |
173 | 236 | "MinSize": "1", |
174 | | - "MaxSize": "4" |
| 237 | + "MaxSize": "4", |
| 238 | + "TargetGroupARNs":[{ "Ref":"ALBTargetGroup" } ] |
175 | 239 | } |
176 | 240 | } |
177 | 241 | } |
|
0 commit comments