AWS CloudFormation RDS 实例创建失败 - 找不到 DBCluster

AWS CloudFormation RDS Instance fails to create - cannot find DBCluster

我正在研究 cloudformation,运行 遇到了一个我无法解决的 DBSubnetGroup 问题。我的目标是建立一个简单的设置:

在 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      

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

现在看起来像:

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

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

我不得不说,我不确定我是否完全理解为什么这解决了这个问题,解释会有所帮助(我已经搜索了一段时间但没有运气)。为什么我不能在此模板中指定我自己的 DBClusterIdentifier?

您的 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 全部小写。

希望您得到 答案 :)