-
Notifications
You must be signed in to change notification settings - Fork 262
/
RDSDatabaseWithOptionalReadReplica.template
142 lines (133 loc) · 5.6 KB
/
RDSDatabaseWithOptionalReadReplica.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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation Sample Template RDSDatabaseWithOptionalReadReplica.template: Sample template showing how to create a highly-available, RDS DBInstance version 5.6 with an optional read replica. **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.t1.micro",
"db.m1.small",
"db.m1.medium",
"db.m1.large",
"db.m1.xlarge",
"db.m2.xlarge",
"db.m2.2xlarge",
"db.m2.4xlarge",
"db.cr1.8xlarge"
],
"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"
},
"MultiAZ": {
"Description": "Multi-AZ master database",
"Type": "String",
"Default": "false",
"AllowedValues": [
"true",
"false"
],
"ConstraintDescription": "must be true or false."
},
"ReadReplica": {
"Description": "Create a read replica",
"Type": "String",
"Default": "false",
"AllowedValues": [
"true",
"false"
],
"ConstraintDescription": "must be true or false."
}
},
"Conditions" : {
"CreateReadReplica" : { "Fn::Equals" : [ {"Ref" : "ReadReplica"}, "true"] }
},
"Resources": {
"MasterDB": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"DBName": { "Ref": "DBName" },
"AllocatedStorage": { "Ref": "DBAllocatedStorage" },
"DBInstanceClass": { "Ref": "DBInstanceClass" },
"Engine": "MySQL",
"EngineVersion": "5.6",
"DBSecurityGroups": [ { "Ref": "DBSecurityGroup" } ],
"MasterUsername": { "Ref": "DBUser" },
"MasterUserPassword": { "Ref": "DBPassword" },
"MultiAZ": { "Ref": "MultiAZ" },
"Tags": [ { "Key": "Name", "Value": "Master Database" } ]
},
"DeletionPolicy": "Snapshot"
},
"ReplicaDB": {
"Type": "AWS::RDS::DBInstance",
"Condition" : "CreateReadReplica",
"Properties": {
"SourceDBInstanceIdentifier": { "Ref": "MasterDB" },
"DBInstanceClass": { "Ref": "DBInstanceClass" },
"Tags": [ { "Key": "Name", "Value": "Read Replica Database" } ]
}
},
"DBSecurityGroup": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
"DBSecurityGroupIngress": { "EC2SecurityGroupName": { "Ref": "EC2SecurityGroup" } },
"GroupDescription": "database access"
}
}
},
"Outputs": {
"MasterJDBCConnectionString": {
"Description": "JDBC connection string for the master database",
"Value": {
"Fn::Join": [ "", [ "jdbc:mysql://", { "Fn::GetAtt": [ "MasterDB", "Endpoint.Address" ] }, ":", { "Fn::GetAtt": [ "MasterDB", "Endpoint.Port" ] }, "/", { "Ref": "DBName" } ] ]
}
},
"ReplicaJDBCConnectionString": {
"Condition" : "CreateReadReplica",
"Description": "JDBC connection string for the replica database",
"Value": { "Fn::Join": [ "", [ "jdbc:mysql://", { "Fn::GetAtt": [ "ReplicaDB", "Endpoint.Address" ] }, ":", { "Fn::GetAtt": [ "ReplicaDB", "Endpoint.Port" ] }, "/", { "Ref": "DBName" } ] ] }
}
}
}