简体   繁体   English

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

[英]How can I know the Name of the “IAM role” attached to EC2 using PowerShell from EC2 Instance itself?

I have an EC2 instance (EC2_Windows_2019_Server_Test) which is attached to an "IAM role".我有一个附加到“IAM 角色”的 EC2 实例 (EC2_Windows_2019_Server_Test)。

How can I know the Name of the "IAM role" attached to EC2 using PowerShell from EC2 Instance itself?如何使用 EC2 实例本身的 PowerShell 知道附加到 EC2 的“IAM 角色”的名称?

Using Powershell you should be able to get from the EC2 instance metadata使用 Powershell 您应该能够从 EC2 实例元数据中获取

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

Can find a list of available metadata here可以在这里找到可用元数据的列表

Thanks to @maafk.感谢@maafk。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM