AWS Cloudformation:如何使用用户名作为标签

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

我需要为ec2实例创建Cloudformation脚本,该ec2实例应具有标签,这些标签指定运行脚本以创建实例的人员的aws用户名。获取IAM用户名的变量名是什么?我的脚本的标记部分如下所示。尽管可以检索AccountId,但无法获取用户名。

    Tags:
    - Key: Name
      Value: !Ref InstanceName
    - Key: team
      Value: !Ref Team
    - Key: awsAccount
      Value: !Sub ${AWS::AccountId}
    - Key: userName
      Value: !Sub ${AWS::IAM::User}
    - Key: purpose
      Value: !Ref Purpose
amazon-web-services amazon-cloudformation aws-cloudformation-custom-resource
1个回答
0
投票

很遗憾没有这样的伪参数在CloudFormation中。所有可用参数的列表,例如AWS::AccountIdhere

解决此问题的一种方法是为您的CloudFormation模板创建parameter(例如,您对Purposeteam所做的操作),例如

Parameters:
    UserName:
      Type: String

并在Tags中引用它:

- Key: userName
  Value: !Ref UserName
© www.soinside.com 2019 - 2024. All rights reserved.