forked from snyk/snyk-iac-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 3
/
aurora.yml
408 lines (360 loc) · 13.2 KB
/
aurora.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
---
AWSTemplateFormatVersion: 2010-09-09
Description: Aurora
# Create the Aurora MySQL or PostgreSQL database(s). Currently, this template only supports alarms for Aurora MySQL.
Parameters:
NetworkStackName:
Description: Name of an active CloudFormation stack that contains networking resources
Type: String
MinLength: 1
MaxLength: 255
AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
DatabaseUser:
Default: startupadmin
Type: String
Description: Database admin account name
MinLength: 5
MaxLength: 16
AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*"
ConstraintDescription: Name must begin with a letter and contain only alphanumeric characters
DatabasePassword:
NoEcho: true
Type: String
Description: Database admin account password
MinLength: 6
MaxLength: 41
AllowedPattern: "[a-zA-Z0-9]*"
ConstraintDescription: Password must contain only alphanumeric characters
DatabaseName:
Default: StartupDB
Type: String
Description: Database name
MinLength: 1
MaxLength: 30
AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*"
ConstraintDescription: Name must begin with a letter and contain only alphanumeric characters
DatabaseEngine:
Default: aurora
Type: String
Description: Database engines - Aurora MySQL or Aurora PostgreSQL
ConstraintDescription: Choose an engine from the drop down
AllowedValues:
- aurora
- aurora-postgresql
EncryptionAtRest:
Default: false
Type: String
Description: The optional flag for encryption at rest (db.t2.small and above)
ConstraintDescription: Only true or false are allowed
AllowedValues:
- true
- false
DatabaseInstanceClass:
Default: db.t2.small
Type: String
Description: "Database instance class, e.g. db.t2.micro (free tier) - Engine support: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html"
ConstraintDescription: DB instance class not supported
AllowedValues:
- db.t2.small
- db.t2.medium
- db.t2.xlarge
- db.r4.large
- db.r4.xlarge
- db.r4.2xlarge
- db.r4.4xlarge
- db.r4.8xlarge
- db.r4.16xlarge
EnvironmentName:
Description: Environment name - dev or prod
Type: String
Default: dev
AllowedValues:
- dev
- prod
ConstraintDescription: Specify either dev or prod
# The database alarm configuration, currently not supported for Aurora PostgreSQL
DatabaseAlarmMaxCpuPercent:
Description: Database CPU % max for alarm (currently, Aurora MySQL only)
Type: Number
Default: 80
MinValue: 1
MaxValue: 99
ConstraintDescription: Must be a percentage between 1-99%
DatabaseAlarmReadLatencyMaxSeconds:
Description: Read latency max for alarm (currently, Aurora MySQL only)
Type: Number
Default: 1
MinValue: 1
DatabaseAlarmWriteLatencyMaxSeconds:
Description: Write latency max for alarm (currently, Aurora MySQL only)
Type: Number
Default: 1
MinValue: 1
DatabaseAlarmEvaluationPeriods:
Description: The number of periods over which data is compared to the specified threshold (currently, Aurora MySQL only)
Type: Number
Default: 2
MinValue: 2
DatabaseAlarmEvaluationPeriodSeconds:
Description: The time over which the specified statistic is applied. Specify time in seconds, in multiples of 60. Enhanced monitoring must be enabled if less than 500 seconds (currently, Aurora MySQL only)
Type: Number
Default: 300
MinValue: 60
ConstraintDescription: Must be at least 60 seconds
EnhancedMonitoring:
Default: false
Type: String
Description: The optional flag for enhanced monitoring (additional charges apply - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.html) (currently, Aurora MySQL only)
ConstraintDescription: Only true or false are allowed
AllowedValues:
- true
- false
# Default is 200 MB
DatabaseAlarmSwapUsageInBytes:
Default: 209715200
Type: Number
Description: Number of swap usage bytes for alarm (if enabled - Aurora MySQL only)
MinValue: 1
ConstraintDescription: Enter a value of at least one byte
EnableAlarms:
Default: false
Type: String
Description: Set to true to enable (additional charges - https://aws.amazon.com/cloudwatch/pricing/ - currently, Aurora MySQL only)
ConstraintDescription: Only true or false are allowed
AllowedValues:
- true
- false
Conditions:
IsProd: !Equals [ !Ref EnvironmentName, prod ]
IsAuroraMySQL: !Equals [ !Ref DatabaseEngine, aurora ]
AlarmsEnabled: !And
- !Condition IsAuroraMySQL
- !Equals [ !Ref EnableAlarms, true ]
EnhancedMonitoringSupprtedAndEnabled: !And
- !Condition AlarmsEnabled
- !Equals [ !Ref EnhancedMonitoring, true ]
Resources:
EnhancedMonitoringRole:
Type: AWS::IAM::Role
Condition: EnhancedMonitoringSupprtedAndEnabled
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: monitoring.rds.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole
DatabaseAlarmTopic:
Type: AWS::SNS::Topic
Condition: AlarmsEnabled
Properties:
DisplayName: Database Alarm Topic
DatabaseSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Database subnet group
SubnetIds:
- Fn::ImportValue: !Sub ${NetworkStackName}-PrivateSubnet1ID
- Fn::ImportValue: !Sub ${NetworkStackName}-PrivateSubnet2ID
Tags:
- Key: Name
Value: !Ref AWS::StackName
AuroraCluster:
Type: AWS::RDS::DBCluster
Properties:
Engine: !Ref DatabaseEngine
MasterUsername: !Ref DatabaseUser
MasterUserPassword: !Ref DatabasePassword
DBSubnetGroupName: !Ref DatabaseSubnetGroup
StorageEncrypted: !Ref EncryptionAtRest
DatabaseName: !Ref DatabaseName
DBClusterParameterGroupName: !If [ IsAuroraMySQL, default.aurora5.6, default.aurora-postgresql9.6 ]
Port: !If [ IsAuroraMySQL, 3306, 5432 ]
VpcSecurityGroupIds:
- Fn::ImportValue: !Sub ${NetworkStackName}-DatabaseGroupID
DependsOn: DatabaseSubnetGroup
AuroraInstance0:
Type: AWS::RDS::DBInstance
Properties:
Engine: !Ref DatabaseEngine
DBClusterIdentifier: !Ref AuroraCluster
DBInstanceClass: !Ref DatabaseInstanceClass
DBSubnetGroupName: !Ref DatabaseSubnetGroup
StorageEncrypted: !Ref EncryptionAtRest
DBParameterGroupName: !If [ IsAuroraMySQL, default.aurora5.6, default.aurora-postgresql9.6 ]
MonitoringInterval: !If [ EnhancedMonitoringSupprtedAndEnabled, 60, 0 ]
MonitoringRoleArn: !If [ EnhancedMonitoringSupprtedAndEnabled, !GetAtt EnhancedMonitoringRole.Arn, !Ref "AWS::NoValue" ]
CopyTagsToSnapshot: true
Tags:
- Key: Name
Value: !Ref AWS::StackName
DependsOn: AuroraCluster
AuroraInstance1:
Type: AWS::RDS::DBInstance
Condition: IsProd
Properties:
Engine: !Ref DatabaseEngine
DBClusterIdentifier: !Ref AuroraCluster
DBInstanceClass: !Ref DatabaseInstanceClass
DBSubnetGroupName: !Ref DatabaseSubnetGroup
StorageEncrypted: !Ref EncryptionAtRest
DBParameterGroupName: !If [ IsAuroraMySQL, default.aurora5.6, default.aurora-postgresql9.6 ]
MonitoringInterval: !If [ EnhancedMonitoringSupprtedAndEnabled, 60, 0 ]
MonitoringRoleArn: !If [ EnhancedMonitoringSupprtedAndEnabled, !GetAtt EnhancedMonitoringRole.Arn, !Ref "AWS::NoValue" ]
CopyTagsToSnapshot: true
Tags:
- Key: Name
Value: !Ref AWS::StackName
DependsOn: AuroraCluster
DatabaseCpuAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB CPU utilization is over ${DatabaseAlarmMaxCpuPercent}% for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: CPUUtilization
Unit: Percent
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmMaxCpuPercent
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBClusterIdentifier
Value: !Ref AuroraCluster
- Name: Role
Value: WRITER
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: AuroraCluster
DatabaseSelectLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB read latency is over ${DatabaseAlarmReadLatencyMaxSeconds} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: SelectLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmReadLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBClusterIdentifier
Value: !Ref AuroraCluster
- Name: Role
Value: WRITER
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: AuroraCluster
DatabaseInsertLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB insert latency is over ${DatabaseAlarmWriteLatencyMaxSeconds} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: InsertLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmWriteLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBClusterIdentifier
Value: !Ref AuroraCluster
- Name: Role
Value: WRITER
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: AuroraCluster
DatabaseUpdateLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB update latency is over ${DatabaseAlarmWriteLatencyMaxSeconds} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: UpdateLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmWriteLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBClusterIdentifier
Value: !Ref AuroraCluster
- Name: Role
Value: WRITER
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: AuroraCluster
DatabaseDeleteLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB update latency is over ${DatabaseAlarmWriteLatencyMaxSeconds} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: DeleteLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmWriteLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBClusterIdentifier
Value: !Ref AuroraCluster
- Name: Role
Value: WRITER
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: AuroraCluster
Outputs:
Name:
Description: Aurora Stack Name
Value: !Ref AWS::StackName
Export:
Name: !Sub ${AWS::StackName}-Name
AuroraClusterId:
Description: Aurora Cluster ID
Value: !Ref AuroraCluster
Export:
Name: !Sub ${AWS::StackName}-AuroraClusterID
AuroraDbURL:
Description: Aurora Database URL
Value: !GetAtt AuroraCluster.Endpoint.Address
Export:
Name: !Sub ${AWS::StackName}-DatabaseURL
AuroraReadDbURL:
Description: Aurora Database Read URL
Value: !GetAtt AuroraCluster.ReadEndpoint.Address
Export:
Name: !Sub ${AWS::StackName}-DatabaseReadURL
DbUser:
Description: RDS Database admin account user
Value: !Ref DatabaseUser
Export:
Name: !Sub ${AWS::StackName}-DatabaseUser
DatabaseAlarmTopicArn:
Description: Database Alarm Topic ARN
Condition: AlarmsEnabled
Value: !Ref DatabaseAlarmTopic
Export:
Name: !Sub ${AWS::StackName}-DatabaseAlarmTopicArn
DatabaseAlarmTopicName:
Description: Database Alarm Topic Name
Condition: AlarmsEnabled
Value: !GetAtt DatabaseAlarmTopic.TopicName
Export:
Name: !Sub ${AWS::StackName}-DatabaseAlarmTopicName