AWS cloudformation使用Fn ::加入列表

use*_*133 4 amazon-web-services aws-cloudformation

我有一个cloudformation模板,该模板使用由lambda函数支持的自定义资源。lambda函数的参数之一是字符串列表。我只有一个项目要传递到列表中,并且想使用Fn:Join串联创建字符串。但是,使用Fn :: Join会导致错误,因为它导致无效的json。任何输入表示赞赏。

“订阅”:[“ Fn :: Join”:[“:”,[“ a”,“ b”,“ c”]]]

调用CreateStack操作时发生客户端错误(ValidationError):模板格式错误:JSON格式不正确。

Cloudformation片段:-

  "Resources": {
"MyCustomRes": {
      "Type": "Custom::CustomResource",
      "Properties": {
        "ServiceToken": { "Fn::Join": [ "", [
                                        "arn:aws:lambda:",
                                        { "Ref": "AWS::Region" },
                                        ":",
                                        { "Ref": "AWS::AccountId" },
                                        ":function:LambdaFn"
                                      ] ] },
        "Version": 1,
        "ResourceName": { "Ref": "ResourceName" },
        "Subscriptions"       : [ "Fn::Join": [ "", [
                                        "arn:aws:sns:",
                                        { "Ref": "AWS::Region" },
                                        ":",
                                        { "Ref": "AWS::AccountId" },
                                        ":Topic1"
                                      ] ] ]
    }
}     },
Run Code Online (Sandbox Code Playgroud)

Tre*_*ton 6

我来到这里寻找 YAML 文件中的相同语法。让我想到的是需要有两个 args 列表:一个包含 2 个要加入的项目的列表,其中第二个是一个列表本身。完整的 YAML 语法如下所示:

  SourceArn: 
    Fn::Join: 
    - ""
    - - 'arn:aws:execute-api:'
      - !Ref AWS::Region
      - ':'
      - !Ref AWS::AccountId
      - ':'
      - !Ref ApiGatewayRestApiResource
      - '/*'
Run Code Online (Sandbox Code Playgroud)


geo*_*ton 5

用于构建 属性值的Fn::Join 内在函数Subscriptions需要是一个对象而不是数组。

使用像这样的数组是无效的JSON语法,['Fn::Join' : [...]]它必须是以下形式 {"Fn::Join" : [...]}

该文档将语法描述为

{ "Fn::Join" : [ "delimiter", [ comma-delimited list of values ] ] }
Run Code Online (Sandbox Code Playgroud)

因此,您的Cloud Formation模板应使用以下内容

    "Subscriptions": {
        "Fn::Join": [":", [
            "arn:aws:sns", 
            { "Ref": "AWS::Region"},
            { "Ref": "AWS::AccountId"},
            "Topic1"]
         ]
     }
Run Code Online (Sandbox Code Playgroud)