问题描述
我的云形成模板中具有以下YML:
I have the following YML in my cloud formation template:
MyDB:
Type: "AWS::RDS::DBInstance"
Properties:
DBInstanceIdentifier: !Ref DBInstanceName
DBName: !Ref DBName
AllocatedStorage: "100"
DBInstanceClass: !Ref DBInstanceType
Engine: "postgres"
EngineVersion: "9.6.2"
MasterUsername: !Ref DBUsername
MasterUserPassword: !Ref DBPassword
PubliclyAccessible: false
StorageType: standard
VPCSecurityGroups:
- !Ref PrivateAccess
MultiAZ: true
DeletionPolicy: "Snapshot"
由于数据库实例和EC2安全组在不同的VPC中。数据库实例在vpc-7c99881b中,而EC2安全组在vpc-34ef9c4d中而失败。
It is failing due to "The DB instance and EC2 security group are in different VPCs. The DB instance is in vpc-7c99881b and the EC2 security group is in vpc-34ef9c4d"
我尝试添加DBSecurityGroup
I tried adding a DBSecurityGroup
DbSecurityByEC2SecurityGroup:
Type: "AWS::RDS::DBSecurityGroup"
Properties:
GroupDescription: "Ingress for Amazon EC2 security group"
DBSecurityGroupIngress:
- EC2SecurityGroupId: !Ref PrivateAccess
并更改了MyDB:
DBSecurityGroups:
- !Ref DbSecurityByEC2SecurityGroup
,但现在说 EC2安全组sg-7debfb0c位于另一个VPC vpc-34ef9c4d中。无法为VPC vpc-7c99881b授予RDS DBSecurityGroup dbsecuritybyec2securitygroup-1whvh0xi93cke的授权。
but it now says "EC2 security group sg-7debfb0c is in a different VPC vpc-34ef9c4d. It cannot be authorized to RDS DBSecurityGroup dbsecuritybyec2securitygroup-1whvh0xi93cke for VPC vpc-7c99881b."
vpc-34ef9c4d是我想要此RDS的vpc,如何指定数据库应该位于VPC?
vpc-34ef9c4d is the vpc i am wanting this RDS in, how do I specify which VPC the DB should be located in?
更新模板:
MyDB:
Type: "AWS::RDS::DBInstance"
Properties:
DBInstanceIdentifier: !Ref DBInstanceName
DBName: !Ref DBName
AllocatedStorage: "100"
DBInstanceClass: !Ref DBInstanceType
Engine: "postgres"
EngineVersion: "9.6.2"
MasterUsername: !Ref DBUsername
MasterUserPassword: !Ref DBPassword
PubliclyAccessible: false
DBSubnetGroupName: !Ref myDBSubnetGroup
StorageType: standard
VPCSecurityGroups:
- !Ref PrivateAccess
MultiAZ: true
DeletionPolicy: "Snapshot"
myDBSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: "description"
SubnetIds:
- !Ref PrivateSubnet
推荐答案
使用DBSubnetGroupName( http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-dbsubnetgroupname )。这决定了VPC。如果未指定任何内容,则会在默认vpc中创建RDS
Use DBSubnetGroupName (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-dbsubnetgroupname). That determines the VPC. If nothing is specified, RDS is created in the default vpc
这篇关于在Cloudformation模板中创建Postgres RDS的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!