如何在CloudFormation脚本中引用现有VPC的VPC Id(之前已在单独的CloudFormation脚本中创建)以便在VPC中创建子网?
In the template defining the VPC, include the VPC ID in the outputs section:
"Outputs" : {
"VPC" : {
"Value" : {"Ref":"VPC"},
"Description" : "VPC ID"
},
...
}
In the template for the stack using the VPC, define a parameter for the VPC ID:
"Parameters" : {
"VPC" : {
"Type" : "String",
},
...
}
When creating this stack, call describe-stack
on the VPC-defining stack to get the ID from outputs, and pass it as the VPC
parameter to create-stack
.
Or get vpc id from input, such as
"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."
},
Reference it by name ie. "VpcId" : { "Ref" : "myVPC" },
In something like:
{
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : String,
"CidrBlock" : String,
"Tags" : [ Resource Tag, ... ],
"VpcId" : { "Ref" : String }
}
}
Documentation here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.