Cloudformation 标签键中的两个内在函数

问题描述 投票:0回答:1

我正在尝试将标签添加到包含另一个堆栈导出的输出的 Cloudformation 资源:

Resources:
  Nodegroup:
    Type: AWS::EKS::Nodegroup
    Properties:
      Tags:
        firstKey: firstValue
        !Sub randomString-${Fn::ImportValue: ClusterName}: true

但是我收到验证错误,因为函数的冒号被解释为值分隔符:

Nested mappings are not allowed in compact mappings

按照建议的引用here没有帮助,因为该函数随后被视为字符串并且不被执行。

我按照文档中的建议尝试了此表单:

!Sub
  - 'randomString-${ClusterName}: true'
  - ClusterName: !ImportValue ClusterName

但是除了获取一个字符串而不是所需的对象之外,我不知道如何添加多个标签。

有办法实现我所需要的吗?

yaml aws-cloudformation
1个回答
0
投票

你可以这样做:

Resources:
  Nodegroup:
    Type: AWS::EKS::Nodegroup
    Properties:
      Tags:
        - Key: firstKey
          Value:
            Fn::Join:
              - ''
              - - 'randomString-'
                - Fn::ImportValue: ClusterName
© www.soinside.com 2019 - 2024. All rights reserved.