如何在AWS Cloudformation模板文件中获取用户名? [英] How to get username in AWS Cloudformation template file?

查看:69
本文介绍了如何在AWS Cloudformation模板文件中获取用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Cloudformation模板文件中定义了带有如下定义标签的资源:

I have resources defined in my Cloudformation template file with tags defined like so:

  "Properties": {
    "Tags": [
      { "Key": "Environment", "Value": {"Ref": "Environment"}},
      { "Key": "Hello", "Value": "World"}
    ]
  }

我的IAM用户名是 my.name 。我想在 Tags 属性中添加一个名为 Creator 的键,其值为我的用户名( my.name )。此外,我需要此值来反映运行此Cloudformation模板的用户的用户名。我该怎么做?

My IAM username is my.name. I would like to add a key named Creator to the Tags property with value my username (my.name). Moreover, I need this value to reflect the username of whoever runs this Cloudformation template. How can I do it?

推荐答案

我不知道有任何直接从模板JSON引用IAM用户名的方法。

I am not aware of any way of referencing the IAM username directly from the template JSON.

但是,您可以使用 get-user 获取用户名(使用CLI或其中一个SDK),然后将其作为参数传递给CloudFormation,或者,如果您以编程方式创建模板JSON,则直接将其插入。

However, you can use get-user to get the username (either using the CLI or one of the SDKs), and then pass it on to CloudFormation as a parameter, or, if you are creating the template JSON programmatically, just insert it directly.

这篇关于如何在AWS Cloudformation模板文件中获取用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆