Cloudformation 合并 Sub 和 Join 得到一个列表

Cloudformation Combine Sub and Join to get a list

我正在尝试在我的 Cloudformation 模板中创建一个列表。

受此启发 post:Sub and Join on Comma-Delimited List 我想到了这个想法,但它不起作用,因为 !Sub 行必须是字符串...

错误是:

Error: Failed to create changeset for the stack: STACKNAME, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.

有什么想法吗?这可能吗?

  Accounts:
    Type: CommaDelimitedList
    Default: Acc1,Acc2,Acc3

  pRedshiftUser:
    Type: String
    Default: arn:redshiftperson

  ...

    Action: sts:AssumeRole
    Condition:
      StringEquals:
        sts:ExternalId: !Split
          - ','
          - !Sub
            - '${pRedshiftUser}/${user}'
            - user: !Join
              - !Sub ',${pRedshiftUser}/'
              - Ref: "Accounts"

我的想法是尝试将其创建为输出:

  Action: sts:AssumeRole
    Condition:
      StringEquals:
        sts:ExternalId:
          - arn:redshiftperson/user1
          - arn:redshiftperson/user2

遗憾的是你不能这样做。 Join 中的 Delimiter 必须是 explicit string

For the Fn::Join delimiter, you can't use any functions. You must specify a string value.

所以你不能在Delimiter中使用Sub

唯一的方法是在 CloudFormation 中创建自定义 macro or a custom resource。在这两种方式中,您都需要开发一个 lambda 函数来处理将数据转换为所需格式的过程。