10

您如何在 CloudFormation 脚本中引用现有 VPC(之前已在单独的 CloudFormation 脚本中创建)的 VPC Id 以便在 VPC 中创建子网?

4

3 回答 3

8

在定义 VPC 的模板中,在输出部分中包含 VPC ID:

"Outputs" : {
    "VPC" : {
        "Value" : {"Ref":"VPC"},
        "Description" : "VPC ID"
    },
    ...
}

在使用 VPC 的堆栈模板中,为 VPC ID 定义一个参数:

"Parameters" : {
    "VPC" : {
        "Type" : "String",
    },
    ...
}

创建此堆栈时,调用describe-stackVPC 定义堆栈以从输出中获取 ID,并将其作为VPC参数传递给create-stack.

于 2015-01-14T01:37:41.603 回答
5

或者从输入中获取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."
    },
于 2016-12-21T06:25:13.617 回答
-2

按名称引用它,即。"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

于 2014-11-03T09:56:55.483 回答