我正在使用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
答案 0 :(得分:1)
我从集群定义中删除了“ DBClusterIdentifier”属性,突然一切正常。希望这一天有帮助。
现在看起来像:
MyRDSCluster:
Type: AWS::RDS::DBCluster
Properties:
BackupRetentionPeriod: 1
DatabaseName: My
DBSubnetGroupName: !Ref MyDBSubnetGroup
Engine: aurora
MasterUsername: exampleUsername
MasterUserPassword: examplePassword
希望这一天有帮助。
我不得不说,我不确定我是否完全理解为什么这可以解决问题,并且做出解释会有所帮助(我一直在寻找运气不好的时候)。为什么我不能在此模板中指定自己的DBClusterIdentifier?
答案 1 :(得分:1)
DBClusterIdentifier名称中的某些字符为大写。 cloudformation的作用是,它将所有大写字符自动转换为小写。 现在,当您尝试将DBInstances附加到DBCluster下时,由于提到的DBClusterIdentifier包含大写字母,因此无法找到它。
<MagicMock spec='str' id='139887652701072'>
解决方案是:将DBClusterIdentifier全部小写。
希望您得到了答案:)