Reputation: 171
I have an EC2 instance (EC2_Windows_2019_Server_Test) which is attached to an "IAM role".
How can I know the Name of the "IAM role" attached to EC2 using PowerShell from EC2 Instance itself?
Upvotes: 0
Views: 1348
Reputation: 6886
Using Powershell you should be able to get from the EC2 instance metadata
$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
Upvotes: 3
Reputation: 171
Thanks to @maafk.
$instanceRole = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/iam/security-credentials/")
Upvotes: 0