[英]AWS Cloudformation: How to use username as a tag
I need to create a Cloudformation Script for an ec2 instance which should have tags specifying among other things, the aws username of the person who ran the script to create the instance.我需要为一个 ec2 实例创建一个 Cloudformation 脚本,该脚本应该具有指定的标签,其中包括运行脚本以创建实例的人的 aws 用户名。 What is the variable name to get the IAM Username?
获取 IAM 用户名的变量名是什么? The tagging part of my script is shown below.
我的脚本的标记部分如下所示。 Whereas the AccountId can be retrieved, I'm unable to get the username.
虽然可以检索 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
Unfortunately there is no such pseudo parameter in CloudFormation.不幸的是,CloudFormation中没有这样的伪参数。 The list of all available parameters, such as
AWS::AccountId
is here .所有可用参数的列表,例如
AWS::AccountId
在这里。
One way around this is to create a parameter for your CloudFormation template (as you do with Purpose
or team
), eg解决此问题的一种方法是为您的 CloudFormation 模板创建一个参数(就像您对
Purpose
或team
所做的那样),例如
Parameters:
UserName:
Type: String
and reference it in your Tags
:并在您的
Tags
中引用它:
- Key: userName
Value: !Ref UserName
One option is to use Service Catalog.一种选择是使用服务目录。 The
aws:servicecatalog:provisioningPrincipalArn
auto tag will be added to all provisioned resources. aws:servicecatalog:provisioningPrincipalArn
自动标签将添加到所有预置资源。
See https://docs.aws.amazon.com/servicecatalog/latest/adminguide/autotags.html请参阅https://docs.aws.amazon.com/servicecatalog/latest/adminguide/autotags.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.