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”

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...