amazon-web-services - 全局 Aurora 数据库的 CloudFormation 模板

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

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

下面是我的代码:

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 ”

实际产量 “
测试全局 Aurora MySQL 5.6.10a global-database-1-cluster-1 主 Aurora MySQL 5.6.10a
global-database-1-instance-1 编写器 Aurora MySQL 5.6.10a ”

最佳答案

我最近遇到了使用 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

关于amazon-web-services - 全局 Aurora 数据库的 CloudFormation 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55928299/

相关文章:

amazon-web-services - AWS Amplify 在 Spring Boot 后端为 https 使用 ssl 证书

mysql - 如何将 RDS 与 phpmyadmin 连接 - AWS

mysql - 如何从 Android 应用程序写入远程数据库

postgresql - 批处理条目 0 INSERT INTO 表错误。可能是什么问题?

aws-cloudformation - 在 Cloudformation 中按名称查找子网 ARN

amazon-web-services - 在存储库的 cloudformation 模板中使用 AWS::CodeBuild::Project 环境变量

amazon-web-services - 无法修改或调整 Amazon EBS 卷的大小

java - 从 amazon s3 存储桶删除文件时出错

sql - redshift-如何插入表格生成的时间序列

amazon-web-services - AWS Java SDK Cloudformation 无法按名称或 ID 描述堆栈