/
castle.yml
514 lines (500 loc) · 22.2 KB
/
castle.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# stacks/apps/castle.yml
# 200A
AWSTemplateFormatVersion: "2010-09-09"
Description: >-
Creates an ECS service for Castle, along with target group and listener rule
for the shared ALB. Also creates a Redis cluster for the service to use.
Parameters:
kContainerName:
Type: String
Default: castle-phoenix
kApplicationPort:
Type: Number
Default: 4000
#######
NestedChangeSetScrubbingResourcesState: { Type: String }
AlbFullName: { Type: String }
AlbHttpsListenerArn: { Type: String }
EcsClusterArn: { Type: String }
EnvironmentType: { Type: String }
EnvironmentTypeAbbreviation: { Type: String }
RegionMode: { Type: String }
RootStackName: { Type: String }
RootStackId: { Type: String }
CloudWatchAlarmTaggerServiceToken: { Type: String }
VpcId: { Type: AWS::EC2::VPC::Id }
VpcPrivateSubnet1Id: { Type: AWS::EC2::Subnet::Id }
VpcPrivateSubnet2Id: { Type: AWS::EC2::Subnet::Id }
VpcPrivateSubnet3Id: { Type: AWS::EC2::Subnet::Id }
NewRelicApiKeyPrxLite: { Type: String }
EcrImageTag: { Type: AWS::SSM::Parameter::Value<String> }
AlbListenerRulePriorityPrefix: { Type: String }
CastlePostgresUsername: { Type: AWS::SSM::Parameter::Value<String> }
CastlePostgresUserPassword: { Type: AWS::SSM::Parameter::Value<String>, NoEcho: true }
SharedRedisReplicationGroupEndpointAddress: { Type: String }
SharedRedisReplicationGroupEndpointPort: { Type: String }
SharedEcsAsgInstanceSecurityGroupId: { Type: AWS::EC2::SecurityGroup::Id }
FeederHostname: { Type: String }
IdHostname: { Type: String }
Conditions:
IsProduction: !Equals [!Ref EnvironmentType, Production]
IsPrimaryRegion: !Equals [!Ref RegionMode, Primary]
EnableNestedChangeSetScrubbingResources: !Equals [!Ref NestedChangeSetScrubbingResourcesState, Enabled]
Resources:
NestedChangeSetScrubber: { Type: AWS::SNS::Topic, Condition: EnableNestedChangeSetScrubbingResources }
HostHeaderListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- TargetGroupArn: !Ref TargetGroup
Type: forward
Conditions:
- Field: host-header
Values:
- castle.*
ListenerArn: !Ref AlbHttpsListenerArn
Priority: !Join ["", [!Ref AlbListenerRulePriorityPrefix, "00"]]
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 15
HealthCheckPath: /api/v1
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 3
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: "30"
Tags:
- { Key: Name, Value: !Sub "${RootStackName}_castle" }
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
TargetType: instance
UnhealthyThresholdCount: 3
VpcId: !Ref VpcId
TargetGroupHttp5xxAlarm:
Type: AWS::CloudWatch::Alarm
Condition: IsProduction
Properties:
AlarmName: !Sub ERROR [Castle] Web server <${EnvironmentTypeAbbreviation}> RETURNING 5XX ERRORS (${RootStackName})
AlarmDescription: !Sub >-
${EnvironmentType} Castle's Elixer server is returning 5XX errors from
the ECS service to the load balancer.
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: LoadBalancer
Value: !Ref AlbFullName
- Name: TargetGroup
Value: !GetAtt TargetGroup.TargetGroupFullName
EvaluationPeriods: 3
MetricName: HTTPCode_Target_5XX_Count
Namespace: AWS/ApplicationELB
Period: 60
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
TargetGroupHttp5xxAlarmTags:
Type: Custom::CloudWatchAlarmTags
Condition: IsProduction
Properties:
ServiceToken: !Ref CloudWatchAlarmTaggerServiceToken
AlarmArn: !GetAtt TargetGroupHttp5xxAlarm.Arn
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:ops:cloudwatch-log-group-name, Value: !Ref TaskLogGroup }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
EcsService:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref EcsClusterArn
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 50
DesiredCount: !If [IsPrimaryRegion, 2, 0]
EnableECSManagedTags: true
LoadBalancers:
- ContainerName: !Ref kContainerName
ContainerPort: !Ref kApplicationPort
TargetGroupArn: !Ref TargetGroup
PropagateTags: TASK_DEFINITION
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
TaskDefinition: !Ref TaskDefinition
TaskLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
RetentionInDays: 14
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
ExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
Policies:
- PolicyDocument:
Statement:
- Action: ssm:GetParameters
Effect: Allow
Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/*
Sid: AllowAppParameterRead
Version: "2012-10-17"
PolicyName: ContainerSecrets
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
TaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Version: "2012-10-17"
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Command:
- web
Cpu: !If [IsProduction, 200, 128]
Environment:
- Name: APP_NAME
Value: castle
- Name: APP_ENV
Value: !Ref EnvironmentTypeAbbreviation
- Name: AWS_DEFAULT_REGION
Value: !Ref AWS::Region
- Name: REDIS_HOST
Value: !Ref SharedRedisReplicationGroupEndpointAddress
- Name: REDIS_PORT
Value: !Ref SharedRedisReplicationGroupEndpointPort
- Name: REDIS_NAMESPACE
Value: castle
- Name: REDIS_POOL_SIZE
Value: "5"
- Name: PORT
Value: !Ref kApplicationPort
- Name: BQ_PROJECT_ID
Value: prx-metrics
- Name: BQ_DATASET
Value: !If [IsProduction, production, staging]
- Name: FEEDER_HOST
Value: !Ref FeederHostname
- Name: ID_HOST
Value: !Ref IdHostname
- Name: NEW_RELIC_LICENSE_KEY
Value: !Ref NewRelicApiKeyPrxLite
- Name: NEW_RELIC_APP_NAME
Value: !If [IsProduction, Castle Production, Castle Staging]
- Name: PG_HOST
Value: !GetAtt PostgresInstance.Endpoint.Address
- Name: PG_PORT
Value: !GetAtt PostgresInstance.Endpoint.Port
- Name: PG_POOL_SIZE
Value: !If [IsProduction, "25", "10"]
Essential: true
Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${EcrImageTag}
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref TaskLogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
Memory: !If [IsProduction, 2000, 1000]
MemoryReservation: !If [IsProduction, 1000, 500]
Name: !Ref kContainerName
PortMappings:
- ContainerPort: !Ref kApplicationPort
HostPort: 0
Secrets:
- Name: SECRET_KEY_BASE
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/secret-key-base
- Name: BQ_CLIENT_EMAIL
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/bigquery-client-email
- Name: BQ_PRIVATE_KEY
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/bigquery-client-key
- Name: CLIENT_ID
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/id-auth-client-id
- Name: CLIENT_SECRET
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/id-auth-client-secret
- Name: MAXMIND_LICENSE_KEY
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/maxmind-license-key
- Name: PG_DATABASE
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/database-name
- Name: PG_PASSWORD
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/database-password
- Name: PG_USER
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Spire/Dovetail-Castle/database-username
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
NetworkMode: bridge
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
TaskRoleArn: !GetAtt TaskRole.Arn
QuicksightVpcSecurityGroup:
Type: AWS::EC2::SecurityGroup
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
GroupDescription: !Sub Castle QuickSight ${EnvironmentType} Security Group
Tags:
- { Key: Name, Value: !Sub "${RootStackName}_castle_postgresql-quicksight" }
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
VpcId: !Ref VpcId
QuicksightVpcSecurityGroupPostgresEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: !Sub >-
Allows outbound PostgreSQL traffic from Quicksight to the
${EnvironmentType} Castle DB
DestinationSecurityGroupId: !GetAtt PostgresSecurityGroup.GroupId
FromPort: 5432
GroupId: !GetAtt QuicksightVpcSecurityGroup.GroupId
IpProtocol: tcp
ToPort: 5432
PostgresParameterGroup:
Type: AWS::RDS::DBParameterGroup
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
Description: !Sub Castle ${EnvironmentType} Parameter Group
Family: postgres13 # aws rds describe-db-engine-versions --query "DBEngineVersions[].DBParameterGroupFamily"
Parameters:
shared_preload_libraries: pg_stat_statements,auto_explain
auto_explain.log_min_duration: "10000"
auto_explain.log_timing: "1"
pg_stat_statements.track: ALL
track_activity_query_size: "4096"
track_io_timing: "1"
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
PostgresSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
DBSubnetGroupDescription: !Sub Castle ${EnvironmentType} Postgres13 Subnet Group
SubnetIds:
- !Ref VpcPrivateSubnet1Id
- !Ref VpcPrivateSubnet2Id
- !Ref VpcPrivateSubnet3Id
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
PostgresSecurityGroup:
Type: AWS::EC2::SecurityGroup
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
GroupDescription: !Sub Castle ${EnvironmentType} Security Group
SecurityGroupIngress:
- FromPort: 5432
IpProtocol: tcp
SourceSecurityGroupId: !Ref SharedEcsAsgInstanceSecurityGroupId
ToPort: 5432
- FromPort: 5432
IpProtocol: tcp
SourceSecurityGroupId: !GetAtt QuicksightVpcSecurityGroup.GroupId
ToPort: 5432
Tags:
- { Key: Name, Value: !Sub "${RootStackName}_castle_postgresql" }
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
VpcId: !Ref VpcId
PostgresSecurityGroupClientIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: Allows inbound traffic from DB client resources
FromPort: 5432
GroupId: !GetAtt PostgresSecurityGroup.GroupId
IpProtocol: tcp
SourceSecurityGroupId: !GetAtt PostgresClientSecurityGroup.GroupId
ToPort: 5432
PostgresInstance:
Type: AWS::RDS::DBInstance
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
AllocatedStorage: !If [IsProduction, "400", "100"]
AllowMajorVersionUpgrade: false
AutoMinorVersionUpgrade: false
BackupRetentionPeriod: 7
CopyTagsToSnapshot: true
DBInstanceClass: !If [IsProduction, db.r6g.2xlarge, db.t4g.medium] # NOTE Changing classes will cause ~10 minutes of downtime
DBName: !If [IsProduction, castle_production, castle_staging]
DBParameterGroupName: !Ref PostgresParameterGroup
DBSubnetGroupName: !Ref PostgresSubnetGroup
DeleteAutomatedBackups: true
DeletionProtection: true
EnablePerformanceInsights: !If [IsProduction, true, false]
Engine: postgres
EngineVersion: "13.4" # aws rds describe-db-engine-versions --engine postgres --query "DBEngineVersions[*].{Engine:Engine,EngineVersion:EngineVersion}" --output text
MasterUsername: !Ref CastlePostgresUsername # Must be 1 to 63 letters or numbers
MasterUserPassword: !Ref CastlePostgresUserPassword # Must contain from 8 to 128 characters
MultiAZ: false
PerformanceInsightsRetentionPeriod: !If [IsProduction, 7, !Ref "AWS::NoValue"]
PreferredBackupWindow: 08:00-08:30
PreferredMaintenanceWindow: tue:06:15-tue:06:45
PubliclyAccessible: false
StorageType: gp2
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
VPCSecurityGroups:
- !GetAtt PostgresSecurityGroup.GroupId
PostgresInstanceDiskSpaceAlarm:
Type: AWS::CloudWatch::Alarm
Condition: IsProduction
Properties:
ActionsEnabled: true
AlarmName: !Sub ERROR [Castle] Database <${EnvironmentTypeAbbreviation}> DISK SPACE LOW (${RootStackName})
AlarmDescription: !Sub >-
${EnvironmentType} Castle's RDS Postgres database instance is running
low on free storage space. If it runs out of space, the Castle app
may encounter operational issues.
ComparisonOperator: LessThanOrEqualToThreshold
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref PostgresInstance
EvaluationPeriods: 1
MetricName: FreeStorageSpace
Namespace: AWS/RDS
Period: 300
Statistic: Average
Threshold: 50000000000
Unit: Bytes
TreatMissingData: notBreaching
# Resources that need access to the Castle DB (clients) belong to this
# security group. It allows traffic to the cluster security group.
# NOTE: This security group can only be used in stacks 300A and higher
PostgresClientSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Sub >-
${EnvironmentType} Castle PostgreSQL client security group
Tags:
- { Key: Name, Value: !Sub "${RootStackName}_castle_postgresql-client" }
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:family, Value: Dovetail }
- { Key: prx:dev:application, Value: Castle }
VpcId: !Ref VpcId
PostgresClientSecurityGroupClusterEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: >-
Allow traffic to the Castle DB security group
DestinationSecurityGroupId: !GetAtt PostgresSecurityGroup.GroupId
FromPort: 5432
GroupId: !GetAtt PostgresClientSecurityGroup.GroupId
IpProtocol: tcp
ToPort: 5432
Outputs:
TargetGroupFullName:
Value: !GetAtt TargetGroup.TargetGroupFullName
PostgresInstanceEndpointAddress:
Value: !GetAtt PostgresInstance.Endpoint.Address
PostgresInstanceEndpointPort:
Value: !GetAtt PostgresInstance.Endpoint.Port
PostgresInstanceId:
Value: !Ref PostgresInstance
QuicksightVpcSecurityGroupId:
Value: !GetAtt QuicksightVpcSecurityGroup.GroupId
PostgresClientSecurityGroupId:
Value: !GetAtt PostgresClientSecurityGroup.GroupId