Cloudformation列表和字符串::属性SecurityGroupIds的值必须为字符串列表类型

时间:2020-07-17 06:57:38

标签: json amazon-ec2 amazon-cloudformation

我遇到以下错误:

"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等各种事物。

2 个答案:

答案 0 :(得分:0)

因为这有效:

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

我推测SecurityGroups是一个采用列表安全组的参数。因此,一次使用SecurityGroupsImportValue将会失败,因为一个是list,另一个是string

因此,您必须构造一个字符串联合列表。虽然在yaml中显示了here的一种方式。您必须将其修改为json格式。

答案 1 :(得分:0)

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

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

这将产生逗号分隔的子网ID列表。