创建子网时,请参考CloudFormation脚本中现有的AWS VPC Id



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

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

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

在使用专有网络的堆栈模板中,为专有网络ID定义一个参数:

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

创建此堆栈时,在VPC定义堆栈上调用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

最新更新