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

标签 json amazon-ec2 aws-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 等。

最佳答案

既然这样有效:

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

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

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

关于json - Cloudformation 列表和字符串::SecurityGroupIds 属性的值必须是字符串列表类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62948717/

相关文章:

c++ - 在 JSON 字符串中序列化 utf-8 字符的标准方法

java - 如何为 imageNameRegex 提供实际的正则表达式

amazon-web-services - 更改 AWS ECS 服务的安全组

amazon-web-services - 当自定义命名的资源需要替换时,CloudFormation 无法更新堆栈

amazon-web-services - 从 SNS 触发 lambda 函数

amazon-web-services - CloudFormation 无法创建 AlexaSkill - 找不到资源

json - 使用 jsonwebtoken 登录安全

json - 使用 angular 开发并模拟所有 json 请求/响应

amazon-web-services - 我是否必须在 AWS Application Load Balancer 后面的 nginx.conf 文件中配置 SSL 证书文件?

json - gulp-nunjucks-html + gulp-data 未在 watch 上编译