Fn :: Sub表达式无法解析为字符串

时间:2018-05-28 06:57:29

标签: amazon-web-services amazon-cloudformation

我创建了一个参数:

Parameters:
  ..
  list:
    Description: "Provide a list .." 
    Type: CommaDelimitedList
    Default: "test1, test2"

现在我想引用这个列表(将在我的cloudformation中的文件中解析" test1"," test2",..),如下所示:

    configure_xx:
      files:        

        /etc/file.conf:
          content: !Sub |
            input {
              logs {
                log_group => [ "${list}" ]
                access_key_id => "${logstashUserKey}"
                secret_access_key => "${logstashUserKey.SecretAccessKey}"
                region => "eu-west-1"
                }
            }

如何使这个参数列表工作? (钥匙工作)。 错误:Fn::Sub expression does not resolve to a string

1 个答案:

答案 0 :(得分:1)

只需切换" String"

的参数类型
Parameters:
  ..
  list:
    Description: "Provide a list .." 
    Type: String
    Default: "test1, test2"

如果由于某种原因,您无法控制此参数类型,则可以使用Fn::Join将列表转换为字符串。例如:

configure_xx:
  files:        

    /etc/file.conf:
      content: 
        Fn::Sub:
        - |-
            input {
              logs {
                log_group => [ "${joinedlist}" ]
                access_key_id => "${logstashUserKey}"
                secret_access_key => "${logstashUserKey.SecretAccessKey}"
                region => "eu-west-1"
                }
            }
        - joinedlist:
            Fn::Join:
            - ', '
            - !Ref list