Mo *_*Ali 10 json amazon-web-services aws-cloudformation troposphere
我正在尝试将列表参数从主模板传递到子模板,但是我遇到了两个错误.这些是我在主模板上的当前参数.
"Parameters": {
"ELBSubnets": {
"Default": "subnet-5d8fea67,subnet-3e35cf15",
"Type": "CommaDelimitedList"
},
"LCKeyPair": {
"Default": "key-master",
"Type": "String"
},
"LCSecurityGroups": {
"Default": "sg-10a15c74,sg-880e5fec",
"Type": "CommaDelimitedList"
}
},
Run Code Online (Sandbox Code Playgroud)
传递给子模板时,它们在同一模板上的此方法中被引用.
"ChildTempate1": {
"Properties": {
"Parameters": {
"ELBSubnets": {
"Ref": "ELBSubnets"
},
"KeyPair": {
"Ref": "LCKeyPair"
},
"LCSecurityGroups": {
"Ref": "LCSecurityGroups"
}
},
Run Code Online (Sandbox Code Playgroud)
在子模板上,它们被声明完全相同.
"Parameters": {
"ELBSubnets": {
"Type": "CommaDelimitedList"
},
"LCKeyPair": {
"Type": "String"
},
"LCSecurityGroups": {
"Type": "CommaDelimitedList"
}
},
Run Code Online (Sandbox Code Playgroud)
并且它们在子模板中的此方法中被引用.
"KeyName": {
"Ref": "LCKeyPair"
},
"SecurityGroups": {
"Fn::Join": [
",",
[
{
"Ref": "LCSecurityGroups"
}
]
]
}
},
Run Code Online (Sandbox Code Playgroud)
这是模板的另一部分.
"Subnets": {
"Fn::Join": [
",",
[
{
"Ref": "ELBSubnets"
}
]
]
}
},
Run Code Online (Sandbox Code Playgroud)
当我尝试在主模板上使用fn :: join时,它说
"模板验证错误:模板错误:每个Fn :: Join对象需要两个参数,(1)字符串分隔符和(2)要连接的字符串列表或返回字符串列表的函数(例如Fn :: GetAZs)加入."
当我不在主模板上使用fn :: join时,错误是
属性值参数必须是具有String(或简单类型)属性的对象
无论我是否在子模板中使用fn :: join相同的参数.
这两个模板都可以在这里找到:https: //github.com/slimg00dy/Troposphere-CloudformationTests
Mo *_*Ali 13
问题是当在CommaDelimitedList上使用Ref时,你传递一个列表,所以它传递"[a,b,c]"而不是"a,b,c"
因此,在主模板上,我使用Join(",")传递列表,使用Join("")传递字符串.这样他们被称为"a,b,c"和"String"
在子模板上,我将参数设置为列表的CommaDelimitedLists和String中的String.这是因为它们从主模板传递的方式.
然后,我在子模板上使用了Ref on the Child模板,而没有使用Join().这将CommaDelimitedLists创建为Lists,并将以Join("")连接的字符串作为字符串传递.
这是我在主模板上的参数声明.
"Parameters": {
"ELBSubnets": {
"Default": "subnet-5d8fea67,subnet-3e35cf15",
"Type": "CommaDelimitedList"
},
"LCKeyPair": {
"Default": "key-master",
"Type": "CommaDelimitedList"
},
"LCSecurityGroups": {
"Default": "sg-10a15c74,sg-880e5fec",
"Type": "CommaDelimitedList"
}
},
Run Code Online (Sandbox Code Playgroud)
这是我如何使用Join(","),Join("")和Ref.由于Ref将CommaDelimitedLists转换为Lists,因此我使用Join(",")将它们保存为CommaDelimitedLists并将它们传递给子模板.
对于KeyPair字符串,我确保它在父模板上被声明为CommaDelimitedList并与Join("")连接,这在引用子模板时有效地使其成为字符串.
"Parameters": {
"ELBSubnets": {
"Fn::Join": [
",",
{
"Ref": "ELBSubnets"
}
]
},
"LCKeyPair": {
"Fn::Join": [
" ",
{
"Ref": "LCKeyPair"
}
]
},
"LCSecurityGroups": {
"Fn::Join": [
",",
{
"Ref": "LCSecurityGroups"
}
]
}
},
Run Code Online (Sandbox Code Playgroud)
在子模板上,它们被声明为这样.
"Parameters": {
"ELBSubnets": {
"Type": "CommaDelimitedList"
},
"LCKeyPair": {
"Type": "String"
},
"LCSecurityGroups": {
"Type": "CommaDelimitedList"
}
},
Run Code Online (Sandbox Code Playgroud)
并且它们都是正常引用而不使用子模板上的Join.
Subnets": {
"Ref": "ELBSubnets"
}
Run Code Online (Sandbox Code Playgroud)
可能有许多不同的方法来做到这一点.我可以在子模板而不是父模板上进行连接.但是我更喜欢保持一个模板复杂,其余模板尽可能干净.希望这有助于其他人.
我也应该能够将列表作为列表传递给子模板,然后我收到错误"未知参数类型:列表"
CommaDelimtedList 只能解析一次,所以在父模板中需要设置类型为“String”,然后在子模板中模板中,保持为 CommaDelimitedList,就像以前一样。
问题正在发生,因为 CloudFormation 正在解析父模板中的 CommaDelimitedList,然后它试图在子模板中再次解析它。
归档时间: |
|
查看次数: |
8688 次 |
最近记录: |