【问题标题】:AWS CloudFormation RDS Instance fails to create - cannot find DBClusterAWS CloudFormation RDS 实例无法创建 - 找不到 DBCluster
【发布时间】:2018-08-31 21:39:05
【问题描述】:

我正在使用 cloudformation 并遇到了我无法解决的 DBSubnetGroup 问题。我的目标是建立一个简单的设置:

  • 具有两个子网的 VPC
  • 这些子网上的 RDS 数据库子网组
  • 该数据库子网中的 RDS 数据库集群
  • 该集群中的单个 RDS 实例

在 cloudformation 中,我不断收到错误消息:

Could not find DB Cluster: MyRDSClusterId (Service: AmazonRDS; Status Code: 
404; Error Code: DBClusterNotFoundFault; Request ID: ...)

在我看来一切正常,cloudformation 说我的 DBCluster 已正确创建。我在这里做错了什么?任何关于我做错了什么的见解将不胜感激。

这是我的 cloudformation 模板:

AWSTemplateFormatVersion: "2010-09-09"
Description: Stack with DBSubnetGroup, DBCluster, and one DBInstance
Resources:
  MyAppVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
  MyAppRDSSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-1a
      VpcId: !Ref MyAppVPC
      CidrBlock: 192.168.0.0/24
      MapPublicIpOnLaunch: true
  MyAppRDSSubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-1b
      VpcId: !Ref MyAppVPC
      CidrBlock: 192.168.1.0/24
      MapPublicIpOnLaunch: true
  MyDBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: My App DBSubnetGroup for RDS
      SubnetIds:
        - !Ref MyAppRDSSubnetA
        - !Ref MyAppRDSSubnetB
  MyRDSCluster:
    Type: AWS::RDS::DBCluster
    Properties:
      BackupRetentionPeriod: 1
      DatabaseName: MyDB
      DBClusterIdentifier: MyRDSClusterId
      DBSubnetGroupName: !Ref MyDBSubnetGroup
      Engine: aurora
      MasterUsername: exampleUsername
      MasterUserPassword: examplePassword
  MyRDSInstance:
    Type: AWS::RDS::DBInstance
    Properties:
      DBClusterIdentifier: !Ref MyRDSCluster
      DBInstanceClass: db.t2.small
      DBSubnetGroupName: !Ref MyDBSubnetGroup
      Engine: aurora      

【问题讨论】:

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


    【解决方案1】:

    您的 DBClusterIdentifier 名称中的某些字符是大写的。 cloudformation 所做的是,它会自动将所有大写字符转换为小写。 现在,当您尝试在 DBCluster 下附加 DBInstances 时,无法使用您提到的 DBClusterIdentifier 找到它,因为它包含一些大写字母。

    MyRDSCluster:
        Type: AWS::RDS::DBCluster
        Properties:
          BackupRetentionPeriod: 1
          DatabaseName: MyDB
          DBClusterIdentifier: MyRDSClusterId <- here it converts all string to lowercase
          DBSubnetGroupName: !Ref MyDBSubnetGroup
          Engine: aurora
          MasterUsername: exampleUsername
          MasterUserPassword: examplePassword
      MyRDSInstance:
        Type: AWS::RDS::DBInstance
        Properties:
          DBClusterIdentifier: !Ref MyRDSCluster <- here it does not, so mismatch in name
          DBInstanceClass: db.t2.small
          DBSubnetGroupName: !Ref MyDBSubnetGroup
          Engine: aurora
    

    解决方法:DBClusterIdentifier 全部小写。

    希望你得到你的答案 :)

    【讨论】:

      【解决方案2】:

      我从集群定义中删除了“DBClusterIdentifier”属性,突然一切正常。希望有一天这对其他人有所帮助。

      现在看起来像:

        MyRDSCluster:
          Type: AWS::RDS::DBCluster
          Properties:
            BackupRetentionPeriod: 1
            DatabaseName: My
            DBSubnetGroupName: !Ref MyDBSubnetGroup
            Engine: aurora
            MasterUsername: exampleUsername
            MasterUserPassword: examplePassword
      

      希望有一天这对其他人有所帮助。

      我不得不说,我不确定我是否完全理解为什么这可以解决问题,并且解释会有所帮助(我一直在寻找一段时间但没有运气)。为什么我不能在这个模板中指定我自己的 DBClusterIdentifier?

      【讨论】:

      • 谢谢!这对我有用。我也不知道为什么,但确实如此。
      • 当您不提及数据库集群标识符时,它会自动采用新生成的集群名称。这可能是它解决了您的问题的原因。另外,我认为这个标识符在那个地区应该是唯一的(不是那么多),
      猜你喜欢
      • 2019-03-21
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2020-12-12
      相关资源
      最近更新 更多