forked from AHinMaine/AWSCloudFormation-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRDS_MySQL_55.template
229 lines (221 loc) · 8.61 KB
/
RDS_MySQL_55.template
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
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template RDS_MySQL_55: Sample template showing how to create a highly-available, RDS DBInstance version 5.5 with alarming on important metrics that indicate the health of the database **WARNING** This template creates an Amazon Relational Database Service database instance and Amazon CloudWatch alarms. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters": {
"DBName": {
"Default": "MyDatabase",
"Description" : "The database name",
"Type": "String",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
},
"DBUser": {
"NoEcho": "true",
"Description" : "The database admin account username",
"Type": "String",
"MinLength": "1",
"MaxLength": "16",
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
},
"DBPassword": {
"NoEcho": "true",
"Description" : "The database admin account password",
"Type": "String",
"MinLength": "8",
"MaxLength": "41",
"AllowedPattern" : "[a-zA-Z0-9]*",
"ConstraintDescription" : "must contain only alphanumeric characters."
},
"DBAllocatedStorage": {
"Default": "5",
"Description" : "The size of the database (Gb)",
"Type": "Number",
"MinValue": "5",
"MaxValue": "1024",
"ConstraintDescription" : "must be between 5 and 1024Gb."
},
"DBInstanceClass": {
"Default": "db.m1.small",
"Description" : "The database instance type",
"Type": "String",
"AllowedValues" : [ "db.m1.small", "db.m1.large", "db.m1.xlarge", "db.m2.xlarge", "db.m2.2xlarge", "db.m2.4xlarge" ],
"ConstraintDescription" : "must select a valid database instance type."
},
"EC2SecurityGroup": {
"Default": "default",
"Description" : "The EC2 security group that contains instances that need access to the database",
"Type": "String"
},
"AlarmTopic": {
"Description": "SNS topic to notify if there are operational issues",
"Type": "String"
},
"MultiAZ": {
"Default": "true",
"Description" : "Create a multi-AZ RDS database instance",
"Type": "String",
"AllowedValues" : [ "true", "false" ],
"ConstraintDescription" : "must be either true or false."
}
},
"Mappings" : {
"InstanceTypeMap" : {
"db.m1.small" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
},
"db.m1.large" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
},
"db.m1.xlarge" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
},
"db.m2.xlarge" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
},
"db.m2.2xlarge" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
},
"db.m2.4xlarge" : {
"CPULimit" : "60",
"FreeStorageSpaceLimit" : "1024",
"ReadIOPSLimit" : "100",
"WriteIOPSLimit" : "100"
}
}
},
"Resources" : {
"MyDB" : {
"Type" : "AWS::RDS::DBInstance",
"Properties" : {
"DBName" : { "Ref" : "DBName" },
"AllocatedStorage" : { "Ref" : "DBAllocatedStorage" },
"DBInstanceClass" : { "Ref" : "DBInstanceClass" },
"Engine" : "MySQL",
"EngineVersion" : "5.5",
"DBSecurityGroups": [ { "Ref": "DBSecurityGroup" } ],
"MasterUsername" : { "Ref" : "DBUser" },
"MasterUserPassword" : { "Ref" : "DBPassword" },
"MultiAZ" : { "Ref" : "MultiAZ" }
},
"DeletionPolicy" : "Snapshot"
},
"DBSecurityGroup": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
"DBSecurityGroupIngress": {
"EC2SecurityGroupName": { "Ref": "EC2SecurityGroup" }
},
"GroupDescription": "database access"
}
},
"CPUAlarmHigh": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": { "Fn::Join" : [ "", ["Alarm if ", { "Ref" : "DBName" }, " CPU > ", { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "CPULimit" ]}, "% for 5 minutes" ]]},
"Namespace": "AWS/RDS",
"MetricName": "CPUUtilization",
"Statistic": "Average",
"Period": "60",
"Threshold": { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "CPULimit" ]},
"ComparisonOperator": "GreaterThanThreshold",
"EvaluationPeriods": "5",
"AlarmActions": [ { "Ref": "AlarmTopic" } ],
"Dimensions": [{
"Name": "DBInstanceIdentifier",
"Value": { "Ref": "MyDB" }
}]
}
},
"FreeStorageSpace": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": { "Fn::Join" : [ "", ["Alarm if ", { "Ref" : "DBName" }, " storage space <= ", { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "FreeStorageSpaceLimit" ]}, " for 5 minutes" ]]},
"Namespace": "AWS/RDS",
"MetricName": "FreeStorageSpace",
"Statistic": "Average",
"Period": "60",
"Threshold": { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "FreeStorageSpaceLimit" ]},
"ComparisonOperator": "LessThanOrEqualToThreshold",
"EvaluationPeriods": "5",
"AlarmActions": [ { "Ref": "AlarmTopic" } ],
"Dimensions": [{
"Name": "DBInstanceIdentifier",
"Value": { "Ref": "MyDB" }
}]
}
},
"ReadIOPSHigh": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": { "Fn::Join" : [ "", ["Alarm if ", { "Ref" : "DBName" }, " WriteIOPs > ", { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "ReadIOPSLimit" ]}, " for 5 minutes" ]]},
"Namespace": "AWS/RDS",
"MetricName": "ReadIOPS",
"Statistic": "Average",
"Period": "60",
"Threshold": { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "ReadIOPSLimit" ]},
"ComparisonOperator": "GreaterThanThreshold",
"EvaluationPeriods": "5",
"AlarmActions": [ { "Ref": "AlarmTopic" } ],
"Dimensions": [{
"Name": "DBInstanceIdentifier",
"Value": { "Ref": "MyDB" }
}]
}
},
"WriteIOPSHigh": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": { "Fn::Join" : [ "", ["Alarm if ", { "Ref" : "DBName" }, " WriteIOPs > ", { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "WriteIOPSLimit" ]}, " for 5 minutes" ]]},
"Namespace": "AWS/RDS",
"MetricName": "WriteIOPS",
"Statistic": "Average",
"Period": "60",
"Threshold": { "Fn::FindInMap" : [ "InstanceTypeMap", { "Ref" : "DBInstanceClass" }, "WriteIOPSLimit" ]},
"ComparisonOperator": "GreaterThanThreshold",
"EvaluationPeriods": "5",
"AlarmActions": [ { "Ref": "AlarmTopic" } ],
"Dimensions": [{
"Name": "DBInstanceIdentifier",
"Value": { "Ref": "MyDB" }
}]
}
}
},
"Outputs" : {
"JDBCConnectionString": {
"Description" : "JDBC connection string for database",
"Value" : { "Fn::Join": [ "", [ "jdbc:mysql://",
{ "Fn::GetAtt": [ "MyDB", "Endpoint.Address" ] },
":",
{ "Fn::GetAtt": [ "MyDB", "Endpoint.Port" ] },
"/",
{ "Ref": "DBName" }]]}
},
"DBAddress" : {
"Description" : "Address of database endpoint",
"Value" : { "Fn::GetAtt": [ "MyDB", "Endpoint.Address" ] }
},
"DBPort" : {
"Description" : "Database endpoint port number",
"Value" : { "Fn::GetAtt": [ "MyDB", "Endpoint.Port" ] }
}
}
}