【发布时间】:2017-03-12 11:37:34
【问题描述】:
我希望我的 CloudFormation 模板使用现有的子网和 VPC。我不想创建新的。
如何参数化这些?
当我查看AWS::EC2::VPC 和AWS::EC2::Subnet 的文档时,似乎这些资源仅用于创建新 VPC 和子网。对吗?
我是否应该将实例资源直接指向我希望它使用的现有 VPC 和子网?
例如 - 如果我的模板中有一个实例资源,并且我将它直接指向现有子网,如下所示:
{
"Resources": {
"MyServer": {
"Type": "AWS::EC2::Instance",
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"SubnetId": {
"Ref": "subnet-abc123"
},
...
验证模板时出现此错误:
Template contains errors.: Template format error: Unresolved resource dependencies [subnet-abc123] in the Resources block of the template
我尝试使用映射执行此操作,但仍然出现错误:
"Mappings": {
"SubnetID": {
"TopKey": {
"Default": "subnet-abc123"
}
}
在实例资源中使用这个:
"SubnetId": {
"Fn::FindInMap": [
"SubnetID",
{
"Ref": "TopKey"
},
"Default"
]
}
我在尝试验证时收到此错误:
Template contains errors.: Template format error: Unresolved resource dependencies [TopKey] in the Resources block of the template
【问题讨论】:
标签: amazon-web-services amazon-ec2 amazon-vpc amazon-cloudformation