【问题标题】:CloudFormation templates for Global Aurora Database全球 Aurora 数据库的 CloudFormation 模板
【发布时间】:2019-04-30 20:32:56
【问题描述】:

我正在尝试编写 Cloudformation 模板来获取 aws 全球 Aurora 数据库。但是,我无法弄清楚在何处以及如何添加全局数据库标识符。有人可以帮助 Cloudformation sn-p 吗?

下面是我的代码:

Description: RDS Aurora MySQL cluster.
Parameters:
    DatabaseName:
      Default: "testglobalaurora"
      Description: The database name 
      Type: String

    DatabaseInstanceType:
        Default: db.r4.large
        AllowedValues:
            - db.r4.large
            - db.r4.xlarge
            - db.r4.2xlarge
            - db.r4.4xlarge
            - db.r4.8xlarge
            - db.r4.16xlarge
        Description: "The instance type to use for the database."
        Type: String

    DatabasePassword:
        Default: "testglobalaurora"
        AllowedPattern: "[a-zA-Z0-9]+"
        ConstraintDescription: must contain only alphanumeric characters. Must have length 8-41.
        Description: The database admin account password. 
        MaxLength: '41'
        MinLength: '8'
        NoEcho: 'true'
        Type: String

    DatabaseUsername:
        Default: "testglobalaurora"
        AllowedPattern: "[a-zA-Z0-9]+"
        ConstraintDescription: must contain only alphanumeric characters. Must have length 1-16
        Description: The database admin account user name. 
        MaxLength: '16'
        MinLength: '1'
        Type: String

Metadata:
    AWS::CloudFormation::Interface:
        ParameterGroups:
            - Label:
                default: Database Configuration
              Parameters:
                - DatabaseInstanceType
                - DatabaseName
                - DatabaseUsername
                - DatabasePassword
        ParameterLabels:
            DatabaseName:
              default: Database name
            DatabaseInstanceType:
                default: Database Instance Type
            DatabasePassword:
                default: Database Password
            DatabaseUsername:
                default: Database Username

Resources:
    ParameterGroup:
        Type: "AWS::RDS::DBParameterGroup"
        Properties: 
            Description: testglobalaurora DB parameter group 
            Family: aurora5.6
            Parameters:
                max_connections: 300

    DatabaseCluster:
        Type: AWS::RDS::DBCluster
        Properties:
            Engine: aurora
            EngineMode: global

            MasterUsername:
              Ref: DatabaseUsername
            MasterUserPassword:
              Ref: DatabasePassword
            BackupRetentionPeriod: 35
            PreferredBackupWindow: 02:00-03:00
            PreferredMaintenanceWindow: mon:03:00-mon:04:00
            VpcSecurityGroupIds:
              - Ref: DatabaseSecurityGroup

    DatabaseInstance:
        Type: AWS::RDS::DBInstance
        Properties:
            Engine: aurora
            EngineVersion : 5.6.10a
            DBClusterIdentifier:
                Ref: DatabaseCluster
            DBInstanceClass:
                Ref: DatabaseInstanceType 
            DBParameterGroupName: !Ref ParameterGroup
            PubliclyAccessible: "true"
            DBInstanceIdentifier: !Ref DatabaseName

    DatabaseSecurityGroup:
        Type: AWS::EC2::SecurityGroup
        Properties: 
            VpcId: vpc-55378f2f
            GroupDescription: Access to database
            SecurityGroupIngress:
                - CidrIp: 0.0.0.0/0
                  FromPort: 3306
                  ToPort: 3306
                  IpProtocol: tcp
            Tags: 
                - Key: Name
                  Value: !Sub ${DatabaseName}-security-group

Outputs:
    DatabaseEndpoint: 
        Description: The database endpoint
        Value: !GetAtt DatabaseCluster.Endpoint.Address

    DatabasePort:
        Description: The database port
        Value: !GetAtt DatabaseCluster.Endpoint.Port

我的输出 "
global-database-1-cluster-1 区域 Aurora MySQL 5.6.10a
global-database-1-instance-1 编写器 Aurora MySQL 5.6.10a "

实际输出 "
test-it 全球极光 MySQL 5.6.10a global-database-1-cluster-1 主 Aurora MySQL 5.6.10a
global-database-1-instance-1 编写器 Aurora MySQL 5.6.10a "

【问题讨论】:

  • 你能解决这个问题吗?目前面临同样的问题
  • 你能解决这个问题吗?有类似的问题stackoverflow.com/questions/56673255/…
  • 我发布了一个新的更新,其中包含我用于全局 RDS 的模板。它没有设置多区域集群,但它是一个开始!

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


【解决方案1】:

我最近遇到了使用 Cloudformation 创建全局 RDS 的需求。这是一个让我入门的最小 Cloudformation。

AWSTemplateFormatVersion: "2010-09-09"
Description: Global RDS database stack
Parameters:
  DatabaseInstanceType:
    Default: db.r4.large
    AllowedValues:
      - db.r4.large
      - db.r4. # add the other r4 instances
    Description: "The instance type to use for the database."
    Type: String
  DatabasePassword:
    Default: SomePassword1
    AllowedPattern: "[a-zA-Z0-9]+"
    ConstraintDescription: must contain only alphanumeric characters. Must have length 8-41.
    Description: The database admin account password.
    MaxLength: '41'
    MinLength: '8'
    NoEcho: 'true'
    Type: String
  DatabaseUsername:
    Default: globaladmin
    ConstraintDescription: must contain only alphanumeric characters. Must have length 1-16
    Description: The database admin account user name.
    MaxLength: '16'
    MinLength: '1'
    Type: String
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      - Label:
          default: Database Configuration
        Parameters:
          - DatabaseInstanceType
          - DatabaseName
          - DatabaseUsername
          - DatabasePassword
    ParameterLabels:
      DatabaseName:
        default: Database name
      DatabaseInstanceType:
        default: Database Instance Type
      DatabasePassword:
        default: Database Password
      DatabaseUsername:
        default: Database Username
Resources:
  GlobalDbCluster:
    Type: AWS::RDS::DBCluster
    Properties:
      Engine: aurora
      EngineMode: global
      EngineVersion: 5.6.10a
      MasterUsername: !Ref DatabaseUsername
      MasterUserPassword: !Ref DatabasePassword
      DBClusterParameterGroupName: !Ref GlobalDbParamGroup
  GlobalDbParamGroup:
    Type: AWS::RDS::DBClusterParameterGroup
    Properties:
      Description: "parameter group for the global database"
      Family: aurora5.6
      Parameters:
        character_set_database: utf32
  InstanceOne:
    Type: AWS::RDS::DBInstance
    Properties:
      DBInstanceClass: !Ref DatabaseInstanceType
      DBClusterIdentifier: !Ref GlobalDbCluster
      Engine: aurora
  InstanceTwo:
    Type: AWS::RDS::DBInstance
    Properties:
      DBInstanceClass: !Ref DatabaseInstanceType
      DBClusterIdentifier: !Ref GlobalDbCluster
      Engine: aurora

【讨论】:

    【解决方案2】:

    您需要使用标识符创建一个全局集群,并在您的数据库集群中使用该标识符。您的 CFN 模板中缺少该部分。

    类似:

    GlobalCluster:
            Type: AWS::RDS::GlobalCluster
            Properties:
                Engine: aurora
                EngineVersion: 5.6.10a
                Region: us-east-1
    

    然后使用 GlobalClusterIdentifier: <id> 在您的 DatabaseCluster 属性中使用它

    但是,查看 RDS 的 CFN 类型 [1] 的官方文档,它没有列出 GlobalCluster。所以要么它只是没有记录,要么这个资源类型没有在 Cloudformation 中注册。如果是后者,那么您可能需要打开支持案例并提出功能请求。

    [1]https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_RDS.html

    【讨论】:

    • 您能否提及您在哪里可以找到AWS::RDS::GlobalCluster 的文档?您在哪里找到有关 GlobalCluster 部分的信息?
    • 真的需要这方面的帮助..还有一个问题stackoverflow.com/questions/56673255/…
    • 就像我在回答中提到的,我认为这是 Aurora 团队需要通过 CFN 支持的东西,如果您还没有为此功能请求打开支持案例,我认为您应该这样做。跨度>
    • 这个链接docs.aws.amazon.com/cli/latest/reference/rds/…没有提到AWS::RDS::GlobalCluster
    • 这就是重点。 GlobalCluster 是处理全球极光数据库的数据结构,它需要注册(通过)CFN,以便您可以使用 AWS::RDS::GlobalCluster。 docs.aws.amazon.com/AmazonRDS/latest/APIReference/…
    猜你喜欢
    • 2019-04-18
    • 2019-07-22
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2020-06-16
    • 2020-09-24
    • 2012-05-09
    • 1970-01-01
    相关资源
    最近更新 更多