如何使用cloudformation模板创建Amazon RDS极光Master并读取副本群集

时间:2016-09-08 06:15:38

标签: amazon-web-services amazon-cloudformation amazon-rds-aurora

使用云形态模板创建Amazon RDS Master并读取副本群集。

1 个答案:

答案 0 :(得分:8)

我们可以使用以下cloudformation模板创建Amazon Aurora RDS。我们需要在创建堆栈时传递参数。

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Aurora Db Stack",
"Parameters": {
    "EnvironmentName": {
        "Description": "The string that will be prefixed to each instance name",
        "Type": "String",
        "MinLength": "3",
        "MaxLength": "6",
        "AllowedPattern": "[a-z0-9]*",
        "ConstraintDescription": "Environment names must be 3-6 characters and contain only a-z and 0-9."
    },
    "DbUsername": {
        "Description": "App Db Username",
        "Type": "String",
        "MinLength": "5",
        "MaxLength": "15",
        "AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
        "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters."
    },
    "DbPassword": {
        "Description": "App Db Password",
        "NoEcho": "true",
        "Type": "String",
        "MinLength": "15",
        "MaxLength": "41",
        "AllowedPattern": "[a-zA-Z0-9]*",
        "ConstraintDescription": "App Db Password must be 15-41 characters and contain only alpha numeric characters."
    },
    "DbType": {
        "Description": "App Db server RDS instance type",
        "Type": "String",
        "Default": "db.r3.large",
        "AllowedValues": [
            "db.r3.large",
            "db.r3.xlarge",
            "db.r3.2xlarge",
            "db.r3.4xlarge",
            "db.r3.8xlarge"
        ],
        "ConstraintDescription": "must be a valid RDS instance type."
    },
    "DBIdentifierNameMaster": {
        "Description": "The string that will be prefixed to each instance name",
        "Type": "String",
        "MinLength": "3",
        "MaxLength": "10",
        "AllowedPattern": "[a-z0-9]*",
        "ConstraintDescription": "Identifier names must be 3-6 characters and contain only a-z and 0-9."
    },
    "DBIdentifierNameReplica": {
        "Description": "The string that will be prefixed to each instance name",
        "Type": "String",
        "MinLength": "3",
        "MaxLength": "10",
        "AllowedPattern": "[a-z0-9]*",
        "ConstraintDescription": "Identifier names must be 3-10 characters and contain only a-z and 0-9."
    },
    "Subnets": {
        "Type": "CommaDelimitedList",
        "Default": "subnet-8ec5b8e6,subnet-1edcc277",
        "Description": "The list of SubnetIds where the stack will be launched"
    },
    "DBSecurityGroupName": {
        "Type": "String",
        "Description": "Security Group id"
    }
},
"Resources": {
    "DBSubnetGroup": {
        "Type": "AWS::RDS::DBSubnetGroup",
        "Properties": {
            "DBSubnetGroupDescription": "Dev DB subent groups",
            "SubnetIds": 
                {
                    "Ref": "Subnets"
                },

            "Tags": [
                {
                    "Key": "Name",
                    "Value": {
                        "Fn::Join": [
                            "",
                            [
                                "PROJECT_NAME-",
                                {
                                    "Ref": "EnvironmentName"
                                },
                                "-db"
                            ]
                        ]
                    }
                }
            ]
        }
    },
    "DBCluster": {
        "Type": "AWS::RDS::DBCluster",
        "Properties": {
            "Engine": "aurora",
            "MasterUsername": {
                "Ref": "DbUsername"
            },
            "MasterUserPassword": {
                "Ref": "DbPassword"
            },
            "DBSubnetGroupName": {
                "Ref": "DBSubnetGroup"
            },
            "VpcSecurityGroupIds": [
                {
                    "Ref": "DBSecurityGroupName"
                }
            ]
        }
    },
    "RDSinstance": {
        "Type": "AWS::RDS::DBInstance",
        "Properties": {
            "DBClusterIdentifier": {
                "Ref": "DBCluster"
            },
            "DBInstanceIdentifier": {
                "Ref": "DBIdentifierNameMaster"
            },
            "DBInstanceClass": {
                "Ref": "DbType"
            },
            "Engine": "aurora",
            "DBParameterGroupName": {
                "Ref": "DbParameterGroup"
            },
            "DBSubnetGroupName": {
                "Ref": "DBSubnetGroup"
            },
            "PubliclyAccessible": "true",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": {
                        "Fn::Join": [
                            "",
                            [
                                "Master Database-",
                                {
                                    "Ref": "EnvironmentName"
                                },
                                "-app-db"
                            ]
                        ]
                    }
                }
            ]
        }
    },
    "RDSinstance2": {
        "Type": "AWS::RDS::DBInstance",
        "Properties": {
            "DBClusterIdentifier": {
                "Ref": "DBCluster"
            },
            "DBInstanceIdentifier": {
                "Ref": "DBIdentifierNameReplica"
            },
            "DBInstanceClass": {
                "Ref": "DbType"
            },
            "Engine": "aurora",
            "DBParameterGroupName": {
                "Ref": "DbParameterGroup"
            },
            "DBSubnetGroupName": {
                "Ref": "DBSubnetGroup"
            },
            "PubliclyAccessible": "true",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": {
                        "Fn::Join": [
                            "",
                            [
                                "Read Replica Database-",
                                {
                                    "Ref": "EnvironmentName"
                                },
                                "-app-db"
                            ]
                        ]
                    }
                }
            ]
        }
    },
    "DbParameterGroup": {
        "Type": "AWS::RDS::DBParameterGroup",
        "Properties": {
            "Description": "AppDbParameters",
            "Family": "aurora5.6",
            "Parameters": {
                "log_bin_trust_function_creators": "on",
                "explicit_defaults_for_timestamp": "0"
            }
        }
    }
}
}