examples/RDS_MySQL_With_Read_Replica.json

{"AWSTemplateFormatVersion":"2010-09-09","Description":"AWS CloudFormation Sample Template RDS_MySQL_With_Read_Replica: Sample template showing how to create a highly-available, RDS DBInstance with a 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":{"Type":"String","Description":"The database name","ConstraintDescription":"must begin with a letter and contain only alphanumeric characters.","Default":"MyDatabase","AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*","MinLength":"1","MaxLength":"64"},"DBUser":{"Type":"String","Description":"The database admin account username","ConstraintDescription":"must begin with a letter and contain only alphanumeric characters.","NoEcho":"True","AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*","MinLength":"1","MaxLength":"16"},"DBPassword":{"Type":"String","Description":"The database admin account password","ConstraintDescription":"must contain only alphanumeric characters.","NoEcho":"True","AllowedPattern":"[a-zA-Z0-9]+","MinLength":"1","MaxLength":"41"},"DBAllocatedStorage":{"Type":"Number","Description":"The size of the database (Gb)","ConstraintDescription":"must be between 5 and 1024Gb.","Default":"5","MinValue":"5","MaxValue":"1024"},"DBInstanceClass":{"Type":"String","Description":"The database instance type","ConstraintDescription":"must select a valid database instance type.","Default":"db.t2.small","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.m3.medium","db.m3.large","db.m3.xlarge","db.m3.2xlarge","db.m4.large","db.m4.xlarge","db.m4.2xlarge","db.m4.4xlarge","db.m4.10xlarge","db.r3.large","db.r3.xlarge","db.r3.2xlarge","db.r3.4xlarge","db.r3.8xlarge","db.m2.xlarge","db.m2.2xlarge","db.m2.4xlarge","db.cr1.8xlarge","db.t2.micro","db.t2.small","db.t2.medium","db.t2.large"]},"EC2SecurityGroup":{"Type":"String","Description":"The EC2 security group that contains instances that need access to the database","ConstraintDescription":"must be a valid security group name.","Default":"default","AllowedPattern":"[a-zA-Z0-9\\-]+"},"MultiAZ":{"Type":"String","Description":"Multi-AZ master database","ConstraintDescription":"must be true or false.","Default":"false","AllowedValues":["true","false"]}},"Conditions":{"Is-EC2-VPC":{"Fn::Or":[{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-central-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"cn-north-1"]}]},"Is-EC2-Classic":{"Fn::Not":[{"Condition":"Is-EC2-VPC"}]}},"Resources":{"DBEC2SecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Condition":"Is-EC2-VPC","Properties":{"GroupDescription":"Open database for access","SecurityGroupIngress":[{"IpProtocol":"tcp","ToPort":"3306","FromPort":"3306","SourceSecurityGroupName":{"Ref":"EC2SecurityGroup"}}]}},"DBSecurityGroup":{"Type":"AWS::RDS::DBSecurityGroup","Condition":"Is-EC2-Classic","Properties":{"DBSecurityGroupIngress":[{"EC2SecurityGroupName":{"Ref":"EC2SecurityGroup"}}],"GroupDescription":"database access"}},"MasterDB":{"Type":"AWS::RDS::DBInstance","DeletionPolicy":"Snapshot","Properties":{"Engine":"MySQL","Tags":[{"Key":"Name","Value":"Master Database"}],"DBName":{"Ref":"DBName"},"AllocatedStorage":{"Ref":"DBAllocatedStorage"},"DBInstanceClass":{"Ref":"DBInstanceClass"},"MasterUsername":{"Ref":"DBUser"},"MasterUserPassword":{"Ref":"DBPassword"},"MultiAZ":{"Ref":"MultiAZ"},"VPCSecurityGroups":{"Fn::If":["Is-EC2-VPC",{"Fn::GetAtt":["DBEC2SecurityGroup","GroupId"]},{"Ref":"AWS::NoValue"}]},"DBSecurityGroups":{"Fn::If":["Is-EC2-Classic",{"Ref":"DBSecurityGroup"},{"Ref":"AWS::NoValue"}]}}},"ReplicaDB":{"Type":"AWS::RDS::DBInstance","Properties":{"Tags":[{"Key":"Name","Value":"Read Replica Database"}],"SourceDBInstanceIdentifier":{"Ref":"MasterDB"},"DBInstanceClass":{"Ref":"DBInstanceClass"}}}},"Outputs":{"EC2Platform":{"Value":"System.Collections.Hashtable","Description":"Platform in which this stack is deployed"},"MasterJDBCConnectionString":{"Value":"System.Collections.Hashtable","Description":"JDBC connection string for the master database"},"ReplicaJDBCConnectionString":{"Value":"System.Collections.Hashtable","Description":"JDBC connection string for the replica database"}}}