How to get username in AWS Cloudformation template file?

只愿长相守 提交于 2019-12-13 13:28:49

问题


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"}
    ]
  }

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?


回答1:


I am not aware of any way of referencing the IAM username directly from the template 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.




回答2:


You should pass the user ID as a parameter on the create-template API call and add it to the tags using Fn::Join. Cloudformation won't do this for you.



来源:https://stackoverflow.com/questions/28727827/how-to-get-username-in-aws-cloudformation-template-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!