【问题标题】:How to create Amazon RDS aurora Master and read replica cluster using cloudformation template如何使用 cloudformation 模板创建 Amazon RDS aurora Master 和只读副本集群
【发布时间】:2017-01-15 23:03:20
【问题描述】:

使用 cloudformation 模板创建 Amazon RDS Master 和只读副本集群。

【问题讨论】:

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


    【解决方案1】:

    我们可以使用以下 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"
                }
            }
        }
    }
    }
    

    【讨论】:

    • 它怎么知道哪个是master?你先定义的那个是主人吗?
    • 您可以指定要命名为主或从的标识符,但在创建集群后,如果有任何故障转移,则读取副本或读取状态将改变,反之亦然。它不会将您的标识符名称用于故障转移。
    猜你喜欢
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 2018-10-10
    • 2021-12-22
    • 2021-07-22
    相关资源
    最近更新 更多