[英]AWS - Merge cloudformation stack with a VPC
I am trying to create a stack in AWS CloudFormation, My template basically consists of Ec2 instance, RDS instance for DB (MySQL engine) and a S3 bucket. 我正在尝试在AWS CloudFormation中创建一个堆栈,我的模板基本上由Ec2实例,用于DB(MySQL引擎)的RDS实例和一个S3存储桶组成。 but, its throwing error stating (db.t2.micro) this DB instance class cannot be created without a VPC, then I changed the DB instance class to (db.m1.small) again am getting same error.
但是,它的抛出错误说明(db.t2.micro)如果没有VPC就无法创建此数据库实例类,那么我将数据库实例类更改为(db.m1.small)再次遇到相同的错误。 I even created a VPC too, but not sure how do I create my stack within the VPC which I created.
我什至也创建了VPC,但不确定如何在创建的VPC中创建堆栈。 I work in my company's AWS account.
我使用公司的AWS账户工作。 where already few other VPCs are available.
其他可用VPC已经很少的地方。
Thanks in advance :) 提前致谢 :)
Modified the JSON script after getting answers. 获取答案后修改了JSON脚本。 This script is in working condition and could create stack.
该脚本处于工作状态,并且可能创建堆栈。 TESTED!
检测过!
Updated Code 更新的代码
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"DBSubnetGroup": {
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "This subnet belongs to Abdul's VPC",
"DBSubnetGroupName": "somename",
"SubnetIds": [
"subnet-f6b15491",
"subnet-b154569e"
]
}
},
"DB": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"AllocatedStorage": "5",
"StorageType": "gp2",
"DBInstanceClass": "db.m1.small",
"DBName": "wordpress",
"Engine": "MySQL",
"MasterUsername": "wordpress",
"MasterUserPassword": "Word12345",
"DBSubnetGroupName": {
"Ref": "DBSubnetGroup"
}
}
},
"EC2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-c481fad3",
"InstanceType": "t2.micro",
"SubnetId": "subnet-b154569e"
}
},
"S3": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "wp-abdultestbuck"
}
}
}
}
You need to create an AWS::RDS::DBSubnetGroup and then reference in the AWS::RDS::DBInstance 您需要创建一个AWS :: RDS :: DBSubnetGroup ,然后在AWS :: RDS :: DBInstance中进行引用
{
"Resources": {
"DBSubnetGroup": {
"Type": "AWS::RDS::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "",
"SubnetIds": [ "<Subnet ID 1","<Subnet ID 2>" ],
}
},
"DB": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
....
"DBSubnetGroupName": { "Ref": "DBSubnetGroup" }
}
},
"EC2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-c481fad3",
"InstanceType": "t2.micro",
"SubnetId": "<SubnetID>"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.