【问题标题】:Cloudformation Lists & Strings :: Value of property SecurityGroupIds must be of type List of StringCloudformation 列表和字符串 :: 属性 SecurityGroupIds 的值必须是字符串列表类型
【发布时间】:2020-11-06 22:47:45
【问题描述】:

我收到以下错误:

"errorMessage": "Stack ID: stack-qenlamel5rn7p1icu Failure Reason: [Instance creation failed with reason: Value of property SecurityGroupIds must be of type List of String, stack-qenlamel5rn7p1icu creation failed with reason: The following resource(s) failed to create: [Instance]. 

我使用的代码是:

            "SecurityGroupIds": [{
                "Fn::ImportValue": {
                    "Fn::Sub": "${EnvIdentifier}-EC2SecurityGroup"
                }
            }, {
                "Ref": "SecurityGroups"
            }], 

如您所见,我同时使用 Ref 和 Fn::ImportValue 来创建单个“字符串列表”。我已经尝试过两者分开并且它们有效。即:

1. Works:
        "SecurityGroupIds" : { "Ref": "SecurityGroups" },

2. Works:
        "SecurityGroupIds" : [ { "Fn::ImportValue" : {"Fn::Sub": "${EnvIdentifier}-EC2SecurityGroup" } } ]

我一起得到了上述错误。尝试了各种方法,例如join 等。

【问题讨论】:

    标签: json amazon-ec2 amazon-cloudformation


    【解决方案1】:

    在 YAML 语法中,我们执行以下操作:

    Value: !Join
        - ','
        - !Ref SubnetId
    

    这会生成以逗号分隔的子网 ID 列表。

    【讨论】:

      【解决方案2】:

      既然这样有效:

      Works: "SecurityGroupIds" : { "Ref": "SecurityGroups" },
      

      我推测SecurityGroups 是一个参数,它采用list 安全组。因此同时使用SecurityGroupsImportValue 将失败,因为一个是list,另一个是string

      因此您必须构建一个连接的字符串列表。一种方法是在yaml 中显示here。您必须将其修改为json 格式。

      【讨论】:

      • 是的,认为您对不同数据类型是我问题的根源是正确的。目前正在度假,我回来时会给你的解决方案。谢谢
      猜你喜欢
      • 2021-12-05
      • 2020-03-25
      • 2019-03-16
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多