-
Notifications
You must be signed in to change notification settings - Fork 25
/
chef_rds.yaml
201 lines (192 loc) · 5.81 KB
/
chef_rds.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Description: Chef Server PostgreSQL v5.1.1
Parameters:
# Required Parameters
VPC:
Description: Choose VPC to use
Type: AWS::EC2::VPC::Id
ChefServerSubnets:
Description: Provide a list of Subnet IDs for the Chef Servers (must be within the specified VPC)
Type: List<AWS::EC2::Subnet::Id>
DBPassword:
Description: Enter DB Password
NoEcho: true
Type: String
ContactEmail:
Description: Contact email for Cloudwatch notifications and instance tagging
Type: String
ContactDept:
Description: Contact department for billing purposes
Type: String
###############################################################################
# Performance Settings
DBInstanceClass:
Description: EC2 Instance type for RDS DBs (M5 class recommended for performance)
Default: 'db.m5.large'
Type: String
AllowedValues:
[
db.t3.small,
db.t3.medium,
db.t3.large,
db.t3.xlarge,
db.t3.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,
db.m5.large,
db.m5.xlarge,
db.m5.2xlarge,
db.m5.4xlarge,
db.m5.12xlarge,
db.m5.24xlarge,
]
DBStorageType:
Description: Select gp2 or io1 DB storage. io1 is much higher performing, must select minimum 100GB storage and an IOPS value
Default: 'gp2'
Type: String
AllowedValues: [gp2, io1]
DBAllocatedStorage:
Description: Storage size allocated for the database
Default: '100'
Type: String
DBIops:
Description: IOPS allocated to the storage (storage size * 10)
Default: '1000'
Type: String
###############################################################################
# Security Settings
FrontendSecurityGroupId:
Description: Supply a security group for your chef frontends
Type: AWS::EC2::SecurityGroup::Id
###############################################################################
# Backup settings
BackupDaystoKeep:
Description: Number of days of automatic backups to keep
Default: 7
Type: Number
MinValue: 0
MaxValue: 35
###############################################################################
# Input from Parent Stack
AlertNotificationTopic:
Description: SNS topic
Type: String
Conditions:
UsePiopsStorage: !Equals [!Ref DBStorageType, 'io1']
Resources:
DBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'RDS Frontend Access'
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId: !Ref FrontendSecurityGroupId
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: RDS DB subnet group
SubnetIds: !Ref ChefServerSubnets
DBPostgres:
Type: AWS::RDS::DBInstance
DeletionPolicy: 'Snapshot'
UpdateReplacePolicy: 'Snapshot'
Properties:
DBName: chef
AllocatedStorage: !Ref DBAllocatedStorage
Iops: !If [UsePiopsStorage, !Ref DBIops, 0]
MasterUsername: chefadmin
MasterUserPassword: !Ref DBPassword
DBInstanceClass: !Ref DBInstanceClass
StorageType: !Ref DBStorageType
MultiAZ: true
Engine: postgres
EngineVersion: 9.6.12
AllowMajorVersionUpgrade: true
AutoMinorVersionUpgrade: true
BackupRetentionPeriod: !Ref BackupDaystoKeep
DBSubnetGroupName: !Ref DBSubnetGroup
VPCSecurityGroups:
- !Ref DBSecurityGroup
PubliclyAccessible: false
Tags:
- Key: Name
Value: !Sub ${AWS::StackName}-pgdb
- Key: X-Dept
Value: !Ref ContactDept
- Key: X-Contact
Value: !Ref ContactEmail
RdsEventSubscription:
Type: AWS::RDS::EventSubscription
Properties:
EventCategories:
- 'availability'
# - "backup"
- 'configuration change'
- 'creation'
- 'deletion'
- 'failover'
- 'failure'
- 'low storage'
- 'maintenance'
- 'notification'
# - "read replica"
- 'recovery'
- 'restoration'
SnsTopicArn: !Ref AlertNotificationTopic
SourceIds:
- !Ref DBPostgres
SourceType: db-instance
# Monitoring
#########################################################################################
RDSWriteLatency:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub RDSWriteLatency-${AWS::StackName}
AlarmDescription: Alarm when RDS write latency is greater than 500ms.
AlarmActions: [!Ref AlertNotificationTopic]
MetricName: WriteLatency
Namespace: AWS/RDS
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 5
Period: 60
Statistic: Average
Threshold: 500
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref DBPostgres
RDSReadLatency:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub RDSReadLatency-${AWS::StackName}
AlarmDescription: Alarm when RDS write latency is greater than a 500ms.
AlarmActions: [!Ref AlertNotificationTopic]
MetricName: ReadLatency
Namespace: AWS/RDS
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Period: 300
Statistic: Average
Threshold: 500
Dimensions:
- Name: DBInstanceIdentifier
Value: !Ref DBPostgres
Outputs:
DBPostgres:
Value: !Ref DBPostgres
Description: The id of the RDS instance created
EndpointAddress:
Value: !GetAtt DBPostgres.Endpoint.Address
Description: The id of the RDS instance created