Search code examples
windowsamazon-web-servicespowershellamazon-ec2aws-powershell

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".

How can I know the Name of the "IAM role" attached to EC2 using PowerShell from EC2 Instance itself?


Solution

  • Thanks to @maafk.

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