-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation.yml
278 lines (260 loc) · 7.72 KB
/
cloudformation.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
AWSTemplateFormatVersion: 2010-09-09
Description: >
Crux Node ECS Stack
Parameters:
NetworkStackName:
Type: String
Description: Name of the Network Stack
Default: network-stack
EcsClusterStackName:
Type: String
Description: Name of the Ecs Cluster Stack
Default: ecs-cluster-stack
SecurityStackName:
Type: String
Description: Name of the Security Stack
Default: security-stack
LoggingStackName:
Description: Name of the Logging Stack
Type: String
Default: logging-stack
EcrDockerImage:
Description: ECR Container Image of the Crux Node
Type: String
Default: database/crux:latest
KafkaBootstrapServer:
Description: Address of the Kafka bootstrap server
Type: String
Default: kafka.callahanwilliam.com:9092
Resources:
CruxLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: 300
- Key: access_logs.s3.enabled
Value: false
- Key: deletion_protection.enabled
Value: false
Name: !Sub ${AWS::StackName}-elb
Scheme: internal
SecurityGroups:
- !Ref CruxLoabBalancerSecurityGroup
Subnets:
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnet1
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnet2
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-elb
Type: application
CruxListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- TargetGroupArn: !Ref CruxTargetGroup
Type: forward
Order: 1
LoadBalancerArn: !Ref CruxLoadBalancer
Port: 3000
Protocol: HTTP
CruxTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: CruxLoadBalancer
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 20
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckPort: 3000
HealthCheckTimeoutSeconds: 15
HealthyThresholdCount: 2
Matcher:
HttpCode: 200
Name: !Sub ${AWS::StackName}-elb-tg
TargetType: ip
Port: 3000
Protocol: HTTP
UnhealthyThresholdCount: 5
VpcId:
Fn::ImportValue:
!Sub ${NetworkStackName}-Vpc
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-elb-tg
CruxService:
Type: AWS::ECS::Service
Properties:
ServiceName: !Sub ${AWS::StackName}
Cluster:
Fn::ImportValue:
!Sub ${EcsClusterStackName}-DatabaseClusterArn
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 50
DeploymentController:
Type: ECS
DesiredCount: 1
LaunchType: FARGATE
TaskDefinition: !Ref CruxTaskDefinition
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- !Ref CruxHostSecurityGroup
Subnets:
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnet1
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnet2
LoadBalancers:
- ContainerName: !Sub ${AWS::StackName}-ecs-cd
ContainerPort: 3000
TargetGroupArn: !Ref CruxTargetGroup
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-ecs-service
CruxTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub ${AWS::StackName}-task
Cpu: 1024
Memory: 2GB
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ContainerDefinitions:
- Name: !Sub ${AWS::StackName}-ecs-cd
DisableNetworking: false
PortMappings:
- ContainerPort: 3000
HostPort: 3000
Protocol: tcp
Privileged: false
ReadonlyRootFilesystem: false
DockerLabels:
Name: !Sub ${AWS::StackName}-task
Essential: true
Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${EcrDockerImage}
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group:
Fn::ImportValue:
!Sub ${LoggingStackName}-DatabaseLogGroupName
awslogs-region: !Sub ${AWS::Region}
awslogs-stream-prefix: !Sub ${AWS::StackName}
Environment:
- Name: HEALTH_CHECK_THRESHOLD
Value: 5
- Name: HEALTH_CHECK_INTERVAL
Value: 6
- Name: HEALTH_CHECK_WAIT_TIME
Value: 5
- Name: KAFKA_BOOTSTRAP_SERVER
Value: !Ref KafkaBootstrapServer
- Name: SERVER_PORT
Value: 3000
ExecutionRoleArn:
Fn::ImportValue:
!Sub ${SecurityStackName}-FargateReadonlyRoleArn
TaskRoleArn:
Fn::ImportValue:
!Sub ${SecurityStackName}-FargateReadonlyRoleArn
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-ecs-cd
CruxLoabBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub ${AWS::StackName}-elb-sg
GroupDescription: Seciruty Group for the Crux Elastic Load Balancer
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3000
ToPort: 3000
SourceSecurityGroupId: !Ref CruxSecurityClientGroup
VpcId:
Fn::ImportValue:
!Sub ${NetworkStackName}-Vpc
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-elb-sg
CruxHostSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub ${AWS::StackName}-host-sg
GroupDescription: Seciruty Group for the Crux Node
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3000
ToPort: 3000
SourceSecurityGroupId: !Ref CruxLoabBalancerSecurityGroup
VpcId:
Fn::ImportValue:
!Sub ${NetworkStackName}-Vpc
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-host-sg
CruxSecurityClientGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub ${AWS::StackName}-client-sg
GroupDescription: Seciruty Group to acceess the Crux Node
VpcId:
Fn::ImportValue:
!Sub ${NetworkStackName}-Vpc
Tags:
- Key: Service
Value: Crux
- Key: Provider
Value: Juxt
- Key: Name
Value: !Sub ${AWS::StackName}-client-sq
Outputs:
CruxSecurityClientGroupName:
Description: Crux Node Client Security Group Name
Value: !Ref CruxSecurityClientGroup
Export:
Name: !Sub ${AWS::StackName}-CruxSecurityClientGroupName
CruxSecurityClientGroupId:
Description: Crux Node Client Security Group Id
Value: !GetAtt CruxSecurityClientGroup.GroupId
Export:
Name: !Sub ${AWS::StackName}-CruxSecurityClientGroupId
CruxLoadBalancerDnsName:
Description: Crux Load Balancer Dns Name
Value: !GetAtt CruxLoadBalancer.DNSName