【问题标题】:How can I know the Name of the "IAM role" attached to EC2 using PowerShell from EC2 Instance itself?如何从 EC2 实例本身使用 PowerShell 知道附加到 EC2 的“IAM 角色”的名称?
【发布时间】:2020-05-19 02:17:05
【问题描述】:

我有一个附加到“IAM 角色”的 EC2 实例 (EC2_Windows_2019_Server_Test)。

我如何知道使用 PowerShell 从 EC2 实例本身附加到 EC2 的“IAM 角色”的名称?

【问题讨论】:

    标签: windows amazon-web-services powershell amazon-ec2 aws-powershell


    【解决方案1】:

    使用 Powershell 您应该能够从 EC2 实例元数据中获取

    $instanceRole = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/iam/security-credentials")
    

    可以找到可用元数据列表here

    【讨论】:

    • 感谢@maafk 的输入。我对您的脚本做了一个小更新(从 URL 中删除了 role-name),并且它起作用了。所以工作脚本是: $instanceRole = (New-Object System.Net.WebClient).DownloadString("169.254.169.254/latest/meta-data/iam/security-credentials/…)
    • 更精简的命令是Invoke-RestMethod http://169.254.169.254/latest/meta-data/iam/security-credentials
    【解决方案2】:

    感谢@maafk。

    $instanceRole = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/iam/security-credentials/")
    

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 2021-07-24
      • 2020-09-02
      • 2021-03-01
      • 2021-09-21
      • 2021-06-21
      • 2019-12-17
      • 2018-07-09
      • 1970-01-01
      相关资源
      最近更新 更多