forked from boosef-snyk/JavaCoffeeShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbs.yml
390 lines (345 loc) · 12 KB
/
dbs.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
---
AWSTemplateFormatVersion: 2010-09-09
Description: RDS
# Database stack creation prerequisite: First create a VPC stack - see README for more info
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
DatabaseSize:
Default: 5
Type: Number
Description: Database storage size in gigabytes (GB)
MinValue: 5
ConstraintDescription: Enter a size of at least 5 GB
# Default is 500 MB
DatabaseAlarmMinFreeSpaceInBytes:
Default: 524288000
Type: Number
Description: Number of min free space bytes for alarm (if enabled)
MinValue: 1
ConstraintDescription: A value of one byte or more
# Default is 200 MB
DatabaseAlarmSwapUsageInBytes:
Default: 209715200
Type: Number
Description: Number of swap usage bytes for alarm (if enabled)
MinValue: 1
ConstraintDescription: A value of one byte or more
DatabaseEngine:
Default: postgres
Type: String
Description: Database engines - PostgreSQL, MariaDB or MySQL
ConstraintDescription: Choose an engine from the drop down
AllowedValues:
- postgres
- mariadb
- mysql
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.micro
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.micro
- db.t2.small
- db.t2.medium
- db.t2.large
- db.t2.xlarge
- db.t2.2xlarge
- db.m4.large
- db.m4.xlarge
- db.m4.2xlarge
- db.m4.4xlarge
- db.m4.10xlarge
- db.m4.16xlarge
- db.r4.large
- db.r4.xlarge
- db.r4.2xlarge
- db.r4.4xlarge
- db.r4.8xlarge
- db.r4.16xlarge
EnvironmentName:
Description: Environment name, either dev or prod
Type: String
Default: dev
AllowedValues:
- dev
- prod
ConstraintDescription: Specify either dev or prod
DatabaseAlarmMaxCpuPercent:
Description: Database CPU % max for alarm
Type: Number
Default: 80
MinValue: 1
MaxValue: 99
ConstraintDescription: Must be a percentage between 1-99%
DatabaseAlarmReadLatencyMaxSeconds:
Description: Read latency max for alarm
Type: Number
Default: 1
MinValue: 1
DatabaseAlarmWriteLatencyMaxSeconds:
Description: Write latency max for alarm
Type: Number
Default: 1
MinValue: 1
DatabaseAlarmEvaluationPeriods:
Description: The number of periods over which data is compared to the specified threshold
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
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)
ConstraintDescription: Only true or false are allowed
AllowedValues:
- true
- false
EnableAlarms:
Default: false
Type: String
Description: Set to true to enable (additional charges - https://aws.amazon.com/cloudwatch/pricing/)
ConstraintDescription: Only true or false are allowed
AllowedValues:
- true
- false
Conditions:
IsProd: !Equals [ !Ref EnvironmentName, prod ]
AlarmsEnabled: !Equals [ !Ref EnableAlarms, true ]
EnhancedMonitoringSupprtedAndEnabled: !And
- !Condition AlarmsEnabled
- !Equals [ !Ref EnhancedMonitoring, true ]
- !Not [ !Equals [ !Ref DatabaseInstanceClass, "db.m1.small" ] ]
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
Database:
Type: AWS::RDS::DBInstance
Properties:
DBSubnetGroupName: !Ref DatabaseSubnetGroup
VPCSecurityGroups:
- Fn::ImportValue: !Sub ${NetworkStackName}-DatabaseGroupID
Engine: !Ref DatabaseEngine
DBName: !Ref DatabaseName
MasterUsername: !Ref DatabaseUser
MasterUserPassword: !Ref DatabasePassword
DBInstanceClass: !Ref DatabaseInstanceClass
AllocatedStorage: !Ref DatabaseSize
StorageType: gp2
MultiAZ: !If [ IsProd, true, false ]
StorageEncrypted: !Ref EncryptionAtRest
MonitoringInterval: !If [ EnhancedMonitoringSupprtedAndEnabled, 60, 0 ]
MonitoringRoleArn: !If [ EnhancedMonitoringSupprtedAndEnabled, !GetAtt EnhancedMonitoringRole.Arn, !Ref "AWS::NoValue" ]
CopyTagsToSnapshot: true
Tags:
- Key: Name
Value: !Ref AWS::StackName
DependsOn: DatabaseSubnetGroup
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: DBInstanceIdentifier
Value: !Ref Database
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: Database
DatabaseFreeStorageSpaceAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB free storage space is less than ${DatabaseAlarmMinFreeSpaceInBytes} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: FreeStorageSpace
Unit: Bytes
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmMinFreeSpaceInBytes
ComparisonOperator: LessThanOrEqualToThreshold
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref Database
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: Database
DatabaseSwapUsageAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB swap usage is greater than than ${DatabaseAlarmSwapUsageInBytes} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: SwapUsage
Unit: Bytes
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmSwapUsageInBytes
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref Database
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: Database
DatabaseReadLatencyAlarm:
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: ReadLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmReadLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref Database
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: Database
DatabaseWriteLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: !Sub DB write latency is over ${DatabaseAlarmWriteLatencyMaxSeconds} for ${DatabaseAlarmEvaluationPeriods} period(s) of ${DatabaseAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
Namespace: AWS/RDS
MetricName: WriteLatency
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref DatabaseAlarmEvaluationPeriods
Period: !Ref DatabaseAlarmEvaluationPeriodSeconds
Threshold: !Ref DatabaseAlarmWriteLatencyMaxSeconds
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref Database
AlarmActions:
- !Ref DatabaseAlarmTopic
DependsOn: Database
Outputs:
Name:
Description: RDS Stack Name
Value: !Ref AWS::StackName
Export:
Name: !Sub ${AWS::StackName}-Name
RdsDbId:
Description: RDS Database ID
Value: !Ref Database
Export:
Name: !Sub ${AWS::StackName}-DatabaseID
RdsDbURL:
Description: RDS Database URL
Value: !GetAtt Database.Endpoint.Address
Export:
Name: !Sub ${AWS::StackName}-DatabaseURL
DbUser:
Description: RDS Database admin account user
Value: !Ref DatabaseUser
Export:
Name: !Sub ${AWS::StackName}-DatabaseUser
DbPassword:
Description: RDS Database admin account password
Value: !Ref DatabasePassword
Export:
Name: !Sub ${AWS::StackName}-DatabasePassword
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