如何在CloudFormation脚本中引用已经在另一个CloudFormation脚本中创建的现有VPC的VPC Id,以便在VPC中创建子网?
"Outputs" : {
"VPC" : {
"Value" : {"Ref":"VPC"},
"Description" : "VPC ID"
},
...
}
"Parameters" : {
"VPC" : {
"Type" : "String",
},
...
}
describe-stack
以获取输出中的ID,并将其作为VPC
参数传递给create-stack
。或者从输入中获取vpc id,例如
"VpcId" : {
"Type" : "AWS::EC2::VPC::Id",
"Description" : "VpcId of your existing Virtual Private Cloud (VPC)",
"ConstraintDescription" : "must be the VPC Id of an existing Virtual Private Cloud."
},
通过名称引用它
例如:"VpcId" : { "Ref" : "myVPC" },
在类似以下的内容中:
{
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : String,
"CidrBlock" : String,
"Tags" : [ Resource Tag, ... ],
"VpcId" : { "Ref" : String }
}
}
文档在这里: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html