【问题标题】:CloudFormation Key Value pair in Environment Variables环境变量中的 CloudFormation 键值对
【发布时间】:2020-03-17 15:03:40
【问题描述】:

我对 AWS 还很陌生,所以我在这里提出的问题可能听起来很基础。我正在尝试定义 cloudformation 模板,并且我需要标记我创建的每个资源。

我可以使用以下方法轻松创建资源和应用标签

Resources:
  ResourceName1:
    Type: AWS::SSM::Parameter
    Properties:
      Name: 'ResourceName1'
      Type: String
      Value: 'Value'
      Tags:
        a: 'some value A'
        b: 'some value B'
        c: 'some value C'
  ResourceName2:
    Type: AWS::SSM::Parameter
    Properties:
      Name: 'ResourceName2'
      Type: String
      Value: 'Value'
      Tags:
        a: 'some value A'
        b: 'some value B'
        c: 'some value C'

在这里,如果我创建多个资源标签将被重复,如果我需要更改标签值,我必须为每个资源更改很多次,所以我在想是否有可能像下面这样我可以外部化标签。

Mappings:
  EnvVariables:
    tags:
    [ a: 'some value A'
      b: 'some value B'
      c: 'some value C'
    ]

Resources:
  ResourceName1:
    Type: AWS::SSM::Parameter
    Properties:
      Name: 'ResourceName1'
      Type: String
      Value: 'Value'
      Tags:
        !FindInMap [EnvVariables, tags]
  ResourceName2:
    Type: AWS::SSM::Parameter
    Properties:
      Name: 'ResourceName2'
      Type: String
      Value: 'Value'
      Tags:
        !FindInMap [EnvVariables, tags]

无论是这种方式,还是有任何其他方法可以将标签外部化到一个地方并从资源中引用它,都可以更轻松地更改标签。

【问题讨论】:

标签: amazon-web-services amazon-cloudformation aws-cloudformation-custom-resource


【解决方案1】:

当您创建 CloudFormation 堆栈时,您可以通过在堆栈选项页面上定义标签或使用 CLI/API.a)b) 中的 --tags 标志将标签与堆栈中支持标签的每个资源关联起来/p>

a)https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-add-tags.html

b)https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-04
    • 2013-10-20
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2017-09-16
    相关资源
    最近更新 更多