1
+ {
2
+ "AWSTemplateFormatVersion" : " 2010-09-09" ,
3
+ "Description" : " AWS CloudFormation template for ecs-cli integ resources." ,
4
+ "Conditions" : {
5
+ "IsCNRegion" : {
6
+ "Fn::Or" : [
7
+ {"Fn::Equals" : [ { "Ref" : " AWS::Region" }, " cn-north-1" ]},
8
+ {"Fn::Equals" : [ { "Ref" : " AWS::Region" }, " cn-northwest-1" ]}
9
+ ]
10
+ }
11
+ },
12
+ "Parameters" : {
13
+ "EcsAmiId" : {
14
+ "Type" : " AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>" ,
15
+ "Description" : " ECS EC2 AMI id" ,
16
+ "Default" : " /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id"
17
+ },
18
+ "EcsPort" : {
19
+ "Type" : " String" ,
20
+ "Description" : " Security Group port to open on ECS instances" ,
21
+ "Default" : " 80"
22
+ },
23
+ "EcsServiceCount" : {
24
+ "Type" : " Number" ,
25
+ "Description" : " Desired task count for the ECS Service" ,
26
+ "Default" : " 3"
27
+ },
28
+ "AsgMinSize" : {
29
+ "Type" : " Number" ,
30
+ "Description" : " Minimum size of ECS Auto Scaling Group" ,
31
+ "Default" : " 0"
32
+ },
33
+ "AsgMaxSize" : {
34
+ "Type" : " Number" ,
35
+ "Description" : " Maximum size of ECS Auto Scaling Group" ,
36
+ "Default" : " 10"
37
+ },
38
+ "AsgDesiredCapacity" : {
39
+ "Type" : " Number" ,
40
+ "Description" : " The initial desired capacity of ECS Auto Scaling Group" ,
41
+ "Default" : " 3"
42
+ }
43
+ },
44
+ "Resources" : {
45
+ "Vpc" : {
46
+ "Type" : " AWS::EC2::VPC" ,
47
+ "Properties" : {
48
+ "CidrBlock" : " 10.0.0.0/16" ,
49
+ "EnableDnsSupport" : true ,
50
+ "EnableDnsHostnames" : true ,
51
+ "Tags" : [ {"Key" : " Name" , "Value" : " ECS CLI Integ cluster" } ]
52
+ }
53
+ },
54
+ "PubSubnetAz1" : {
55
+ "Type" : " AWS::EC2::Subnet" ,
56
+ "Properties" : {
57
+ "CidrBlock" : " 10.0.0.0/24" ,
58
+ "Tags" : [ {"Key" : " Name" , "Value" : " ECS CLI Integ cluster" } ],
59
+ "VpcId" : {
60
+ "Ref" : " Vpc"
61
+ }
62
+ }
63
+ },
64
+ "PubSubnetAz2" : {
65
+ "Type" : " AWS::EC2::Subnet" ,
66
+ "Properties" : {
67
+ "CidrBlock" : " 10.0.1.0/24" ,
68
+ "Tags" : [ {"Key" : " Name" , "Value" : " ECS CLI Integ cluster" } ],
69
+ "VpcId" : {
70
+ "Ref" : " Vpc"
71
+ }
72
+ }
73
+ },
74
+ "InternetGateway" : {
75
+ "Type" : " AWS::EC2::InternetGateway" ,
76
+ "Properties" : {
77
+ "Tags" : [ {"Key" : " Name" , "Value" : " ECS CLI Integ cluster" } ]
78
+ }
79
+ },
80
+ "AttachGateway" : {
81
+ "Type" : " AWS::EC2::VPCGatewayAttachment" ,
82
+ "Properties" : {
83
+ "VpcId" : {
84
+ "Ref" : " Vpc"
85
+ },
86
+ "InternetGatewayId" : {
87
+ "Ref" : " InternetGateway"
88
+ }
89
+ }
90
+ },
91
+ "RouteViaIgw" : {
92
+ "Type" : " AWS::EC2::RouteTable" ,
93
+ "Properties" : {
94
+ "VpcId" : {
95
+ "Ref" : " Vpc"
96
+ }
97
+ }
98
+ },
99
+ "PublicRouteViaIgw" : {
100
+ "Type" : " AWS::EC2::Route" ,
101
+ "Properties" : {
102
+ "RouteTableId" : {
103
+ "Ref" : " RouteViaIgw"
104
+ },
105
+ "DestinationCidrBlock" : " 0.0.0.0/0" ,
106
+ "GatewayId" : {
107
+ "Ref" : " InternetGateway"
108
+ }
109
+ }
110
+ },
111
+ "PubSubnet1RouteTableAssociation" : {
112
+ "Type" : " AWS::EC2::SubnetRouteTableAssociation" ,
113
+ "Properties" : {
114
+ "SubnetId" : {
115
+ "Ref" : " PubSubnetAz1"
116
+ },
117
+ "RouteTableId" : {
118
+ "Ref" : " RouteViaIgw"
119
+ }
120
+ }
121
+ },
122
+ "PubSubnet2RouteTableAssociation" : {
123
+ "Type" : " AWS::EC2::SubnetRouteTableAssociation" ,
124
+ "Properties" : {
125
+ "SubnetId" : {
126
+ "Ref" : " PubSubnetAz2"
127
+ },
128
+ "RouteTableId" : {
129
+ "Ref" : " RouteViaIgw"
130
+ }
131
+ }
132
+ },
133
+ "EcsSecurityGroup" : {
134
+ "Type" : " AWS::EC2::SecurityGroup" ,
135
+ "Properties" : {
136
+ "GroupDescription" : " ECS Allowed Ports" ,
137
+ "VpcId" : {
138
+ "Ref" : " Vpc"
139
+ },
140
+ "SecurityGroupIngress" : [{
141
+ "IpProtocol" : " tcp" ,
142
+ "FromPort" : " 80" ,
143
+ "ToPort" : " 80" ,
144
+ "CidrIp" : " 0.0.0.0/0"
145
+ }]
146
+ }
147
+ },
148
+ "EcsInstanceRole" : {
149
+ "Type" : " AWS::IAM::Role" ,
150
+ "Properties" : {
151
+ "AssumeRolePolicyDocument" : {
152
+ "Version" : " 2012-10-17" ,
153
+ "Statement" : [
154
+ {
155
+ "Effect" : " Allow" ,
156
+ "Principal" : {
157
+ "Service" : [
158
+ "Fn::If" : [
159
+ " IsCNRegion" ,
160
+ " ec2.amazonaws.com.cn" ,
161
+ " ec2.amazonaws.com"
162
+ ]
163
+ ]
164
+ },
165
+ "Action" : [
166
+ " sts:AssumeRole"
167
+ ]
168
+ }
169
+ ]
170
+ },
171
+ "ManagedPolicyArns" : [
172
+ " arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
173
+ ]
174
+ }
175
+ },
176
+ "EcsInstanceProfile" : {
177
+ "Type" : " AWS::IAM::InstanceProfile" ,
178
+ "Properties" : {
179
+ "Roles" : [{ "Ref" : " EcsInstanceRole" }]
180
+ }
181
+ },
182
+ "EcsInstanceLc" : {
183
+ "Type" : " AWS::AutoScaling::LaunchConfiguration" ,
184
+ "Properties" : {
185
+ "AssociatePublicIpAddress" : true ,
186
+ "ImageId" : {
187
+ "Ref" : " EcsAmiId"
188
+ },
189
+ "InstanceType" : " m5.large" ,
190
+ "IamInstanceProfile" : {
191
+ "Ref" : " EcsInstanceProfile"
192
+ },
193
+ "SecurityGroups" : [{
194
+ "Ref" : " EcsSecurityGroup"
195
+ }],
196
+ "UserData" : {
197
+ "Fn::Base64" : {
198
+ "Fn::Join" : [" " , [
199
+ " #!/bin/bash\n " ,
200
+ " echo ECS_CLUSTER=ecs-cli-integ >> /etc/ecs/ecs.config"
201
+ ]]
202
+ }
203
+ }
204
+ }
205
+ },
206
+ "EcsInstanceAsg" : {
207
+ "Type" : " AWS::AutoScaling::AutoScalingGroup" ,
208
+ "Properties" : {
209
+ "VPCZoneIdentifier" : [{ "Ref" : " PubSubnetAz1" }, {"Ref" : " PubSubnetAz2" }],
210
+ "LaunchConfigurationName" : {
211
+ "Ref" : " EcsInstanceLc"
212
+ },
213
+ "MinSize" : {
214
+ "Ref" : " AsgMinSize"
215
+ },
216
+ "MaxSize" : {
217
+ "Ref" : " AsgMaxSize"
218
+ },
219
+ "DesiredCapacity" : {
220
+ "Ref" : " AsgDesiredCapacity"
221
+ },
222
+ "Tags" : [
223
+ {
224
+ "Key" : " Name" ,
225
+ "Value" : " ECS CLI Integ cluster" ,
226
+ "PropagateAtLaunch" : true
227
+ }
228
+ ]
229
+ }
230
+ },
231
+ "EcsCluster" : {
232
+ "Type" : " AWS::ECS::Cluster" ,
233
+ "Properties" : {
234
+ "ClusterName" : " ecs-cli-integ"
235
+ }
236
+ },
237
+ "EcsTaskDefinition" : {
238
+ "Type" : " AWS::ECS::TaskDefinition" ,
239
+ "Properties" : {
240
+ "Family" : " ecs-cli-integ" ,
241
+ "Memory" : " 1GB" ,
242
+ "NetworkMode" : " awsvpc" ,
243
+ "Cpu" : " 512" ,
244
+ "RequiresCompatibilities" : [" EC2" , " FARGATE" ],
245
+ "ContainerDefinitions" : [{
246
+ "Name" : " httpd" ,
247
+ "Image" : " httpd" ,
248
+ "PortMappings" : [{
249
+ "ContainerPort" : " 80"
250
+ }]
251
+ }]
252
+ }
253
+ },
254
+ "EcsService" : {
255
+ "Type" : " AWS::ECS::Service" ,
256
+ "Properties" : {
257
+ "Cluster" : { "Ref" : " EcsCluster" },
258
+ "DesiredCount" : { "Ref" : " EcsServiceCount" },
259
+ "ServiceName" : " ecs-cli-integ-service" ,
260
+ "TaskDefinition" : { "Ref" : " EcsTaskDefinition" },
261
+ "NetworkConfiguration" : {
262
+ "AwsvpcConfiguration" : {
263
+ "AssignPublicIp" : " DISABLED" ,
264
+ "SecurityGroups" : [{ "Ref" : " EcsSecurityGroup" }],
265
+ "Subnets" : [{ "Ref" : " PubSubnetAz1" }, { "Ref" : " PubSubnetAz2" }]
266
+ }
267
+ }
268
+ }
269
+ }
270
+ }
271
+ }
0 commit comments