-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcluster.cfn.yml
249 lines (246 loc) · 6.17 KB
/
cluster.cfn.yml
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
AWSTemplateFormatVersion: 2010-09-09
Description: Test Docker deployment
Mappings:
AWSRegionToAMI:
ap-northeast-1:
AMIID: ami-30bdce57
ap-southeast-1:
AMIID: ami-9f75ddfc
ap-southeast-2:
AMIID: ami-cf393cac
ca-central-1:
AMIID: ami-1b01b37f
eu-central-1:
AMIID: ami-38dc1157
eu-west-1:
AMIID: ami-e3fbd290
eu-west-2:
AMIID: ami-77f6fc13
us-east-1:
AMIID: ami-a58760b3
us-east-2:
AMIID: ami-a6e4bec3
us-west-1:
AMIID: ami-74cb9b14
us-west-2:
AMIID: ami-5b6dde3b
Outputs:
ClusterId:
Description: ClusterId
Export:
Name:
Fn::Sub: ${AWS::StackName}-ClusterId
Value:
Ref: ECSCluster
PublicSecurityGroup:
Description: SecurityGroup
Export:
Name:
Fn::Sub: ${AWS::StackName}-SecurityGroup
Value:
Ref: PublicSecurityGroup
Parameters:
DesiredCapacity:
Default: 1
Description: Number of instances to launch in your ECS cluster.
Type: Number
InstanceType:
AllowedValues:
- t2.micro
- t2.small
- t2.medium
- t2.large
- m3.medium
- m3.large
- m3.xlarge
- m3.2xlarge
- m4.large
- m4.xlarge
- m4.2xlarge
- m4.4xlarge
- m4.10xlarge
- c4.large
- c4.xlarge
- c4.2xlarge
- c4.4xlarge
- c4.8xlarge
- c3.large
- c3.xlarge
- c3.2xlarge
- c3.4xlarge
- c3.8xlarge
- r3.large
- r3.xlarge
- r3.2xlarge
- r3.4xlarge
- r3.8xlarge
- i2.xlarge
- i2.2xlarge
- i2.4xlarge
- i2.8xlarge
ConstraintDescription: Please choose a valid instance type.
Default: t2.micro
Description: EC2 instance type
Type: String
MaxSize:
Default: 1
Description: Maximum number of instances that can be launched in your ECS cluster.
Type: Number
VPCId:
Description: Name of the stack containing a VPC with at least two subnets
Type: AWS::EC2::VPC::Id
VPCZoneIdentifier:
Description: Name of the stack containing a VPC with at least two subnets
Type: CommaDelimitedList
Resources:
AutoScalingGroup:
CreationPolicy:
ResourceSignal:
Timeout: PT5M
Properties:
DesiredCapacity:
Ref: DesiredCapacity
LaunchConfigurationName:
Ref: LaunchConfiguration
MaxSize:
Ref: MaxSize
MinSize: "1"
VPCZoneIdentifier:
Ref: VPCZoneIdentifier
Type: AWS::AutoScaling::AutoScalingGroup
UpdatePolicy:
AutoScalingReplacingUpdate:
PauseTime: PT5M
WillReplace: "true"
AutoscalingRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- application-autoscaling.amazonaws.com
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- application-autoscaling:*
- cloudwatch:DescribeAlarms
- cloudwatch:PutMetricAlarm
- ecs:DescribeServices
- ecs:UpdateService
Effect: Allow
Resource: '*'
PolicyName: ecs-service-autoscaling
Type: AWS::IAM::Role
EC2InstanceProfile:
Properties:
Path: /
Roles:
- Ref: ECSInstanceRole
Type: AWS::IAM::InstanceProfile
ECSCluster:
Type: AWS::ECS::Cluster
ECSInstanceRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- ecs:CreateCluster
- ecs:DeregisterContainerInstance
- ecs:DiscoverPollEndpoint
- ecs:Poll
- ecs:RegisterContainerInstance
- ecs:StartTelemetrySession
- ecs:Submit*
- ecr:BatchCheckLayerAvailability
- ecr:BatchGetImage
- ecr:GetDownloadUrlForLayer
- ecr:GetAuthorizationToken
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: '*'
PolicyName: ecs-service-instance
Type: AWS::IAM::Role
LaunchConfiguration:
Properties:
AssociatePublicIpAddress: true
IamInstanceProfile:
Ref: EC2InstanceProfile
ImageId:
Fn::FindInMap:
- AWSRegionToAMI
- Ref: AWS::Region
- AMIID
InstanceType:
Ref: InstanceType
KeyName: ecs-instance
SecurityGroups:
- Ref: PublicSecurityGroup
UserData:
Fn::Base64:
Fn::Sub: |
#!/bin/bash -xe
yum install -y aws-cfn-bootstrap
#!/bin/bash -xe
echo ECS_CLUSTER=${ECSCluster} >> /etc/ecs/ecs.config
# /opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource ECSAutoScalingLaunchConfig --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource AutoScalingGroup --region ${AWS::Region}
Type: AWS::AutoScaling::LaunchConfiguration
PublicSecurityGroup:
Properties:
GroupDescription: ECS Public Security Group
VpcId:
Ref: VPCId
Type: AWS::EC2::SecurityGroup
PublicSecurityGroupDynamicPorts:
Properties:
FromPort: 31000
GroupId:
Ref: PublicSecurityGroup
IpProtocol: tcp
SourceSecurityGroupId:
Ref: PublicSecurityGroup
ToPort: 61000
Type: AWS::EC2::SecurityGroupIngress
PublicSecurityGroupHTTPInbound:
Properties:
CidrIp: 0.0.0.0/0
FromPort: "80"
GroupId:
Ref: PublicSecurityGroup
IpProtocol: tcp
ToPort: "80"
Type: AWS::EC2::SecurityGroupIngress
PublicSecurityGroupHTTPSInbound:
Properties:
CidrIp: 0.0.0.0/0
FromPort: "443"
GroupId:
Ref: PublicSecurityGroup
IpProtocol: tcp
ToPort: "443"
Type: AWS::EC2::SecurityGroupIngress
PublicSecurityGroupSSHInbound:
Properties:
CidrIp: 0.0.0.0/0
FromPort: "22"
GroupId:
Ref: PublicSecurityGroup
IpProtocol: tcp
ToPort: "22"
Type: AWS::EC2::SecurityGroupIngress