2014-11-03 39 views

回答

-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

+0

它看起来像我需要有一个参数或映射,然后硬编码的VPC ID,然后在子网脚本,除非VPC引用它和子网全部使用相同的脚本创建,以便能够使用“VpcId”引用VPC ID:{“Ref”:“myVPC”}。 – Roobie 2014-11-04 22:12:43

+1

如果你已经有一个VPC它将有一个Id只是把它放在参考。即“VpcId”:{“参考”:“vpc-123456”} – 2014-11-06 11:02:45

+1

不起作用:模板验证错误:模板格式错误:未解决的资源依赖关系... – Ashesh 2015-09-04 17:40:06

7

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

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

在模板为使用VPC堆叠,为VPC ID定义参数:

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

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

+0

基本上是正确的 - 但“类型”不能简单地为VPC字符串,它必须是“AWS :: EC2 :: VPC :: Id”,就像这里记录:http ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html – jebbie 2017-06-07 22:02:52

+0

字符串应该可以正常工作(或者至少在我编写此代码时),但使用更具体的类型更好。谢谢。 – bsvingen 2017-06-08 22:15:59

+0

至少在我现在使用的最新awscli中,它将失败,在不使用此特定类型的模板上发生验证错误;) – jebbie 2017-06-12 17:25:14

2

或者从输入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." 
    }, 
相关问题