微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

json – 尝试将参数从Master传递到子模板

我正在尝试将列表参数从主模板传递到子模板,但是我遇到了两个错误..这些是我在主模板上的当前参数.
"Parameters": {
    "ELBsubnets": {
        "Default": "subnet-5d8fea67,subnet-3e35cf15","Type": "CommaDelimitedList"
    },"LCKeyPair": {
        "Default": "key-master","Type": "String"
    },"LCSecurityGroups": {
        "Default": "sg-10a15c74,sg-880e5fec","Type": "CommaDelimitedList"
    }
},

传递给子模板时,它们在同一模板上的此方法中被引用.

"ChildTempate1": {
        "Properties": {
            "Parameters": {
                "ELBsubnets": {
                    "Ref": "ELBsubnets"
                },"KeyPair": {
                    "Ref": "LCKeyPair"
                },"LCSecurityGroups": {
                    "Ref": "LCSecurityGroups"
                }
            },

在子模板上,它们被声明完全相同.

"Parameters": {
    "ELBsubnets": {
        "Type": "CommaDelimitedList"
    },"LCKeyPair": {
        "Type": "String"
    },"LCSecurityGroups": {
        "Type": "CommaDelimitedList"
    }
},

并且它们在子模板中的此方法中被引用.

"KeyName": {
                "Ref": "LCKeyPair"
            },"SecurityGroups": {
                "Fn::Join": [
                    ",",[
                        {
                            "Ref": "LCSecurityGroups"
                        }
                    ]
                ]
            }
        },

这是模板的另一部分.

"subnets": {
                "Fn::Join": [
                    ",[
                        {
                            "Ref": "ELBsubnets"
                        }
                    ]
                ]
            }
        },

当我尝试在主模板上使用fn :: join时,它说

“Template validation error: Template error: every Fn::Join object requires two parameters,(1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.”

当我不在主模板上使用fn :: join时,错误

Value of property Parameters must be an object with String (or simple type) properties

无论我是否在子模板中使用fn :: join相同的参数.

这两个模板都可以在这里找到:https://github.com/slimg00dy/Troposphere-CloudformationTests

解决方法

问题是当在CommaDelimitedList上使用Ref时,你传递一个列表,所以它传递“[a,b,c]”而不是“a,c”

因此,在主模板上,我使用Join(“,”)传递列表,使用Join(“”)传递字符串.这样它们被称为“a,c”和“String”

在子模板上,我将参数设置为列表的CommaDelimitedLists和String中的String.这是因为它们从主模板传递的方式.

然后我在子模板上使用Ref on the Child模板而不使用Join().这将CommaDelimitedLists创建为Lists,并将以Join(“”)连接的字符串作为字符串传递.

这是我在主模板上的参数声明.

"Parameters": {
    "ELBsubnets": {
        "Default": "subnet-5d8fea67,

这是我如何使用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"
                        }
                    ]
                }
            },它们被声明为这样.

"Parameters": {
    "ELBsubnets": {
        "Type": "CommaDelimitedList"
    },

并且它们都是正常引用而不使用子模板上的Join.

subnets": {
                "Ref": "ELBsubnets"
            }

可能有很多不同的方法可以做到这一点.我可以在子模板而不是父模板上进行连接.但是,我更喜欢保持一个模板复杂,其余模板尽可能干净.希望这有助于其他人.

我也应该能够将列表作为列表传递给子模板,然后我收到错误“UnkNown parameter type:List”

原文地址:https://www.jb51.cc/js/157420.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐