简体   繁体   English

在创建子网时引用CloudFormation脚本中的现有AWS VPC Id

[英]Reference an existing AWS VPC Id in CloudFormation script when creating subnets

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

In the template defining the VPC, include the VPC ID in the outputs section: 在定义VPC的模板中,在输出部分中包含VPC ID:

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

In the template for the stack using the VPC, define a parameter for the VPC ID: 在使用VPC的堆栈模板中,为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 . 创建此堆栈时,在VPC定义describe-stack上调用describe-stack以从输出中获取ID,并将其作为VPC参数传递给create-stack

Or get vpc id from input, such as 或者从输入中获取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."
    },

Reference it by name ie. 按名称引用它即。 "VpcId" : { "Ref" : "myVPC" }, In something like: "VpcId" : { "Ref" : "myVPC" },类似于:

    {
   "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 这里的文档: http//docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM