How to get iam role (instance profile) attached to the instance from within an ec2 instance?

You can use AWS EC2 metadata service to get iam role (instance profile) attached to the instance from within an ec2 instance.
The link to EC2 metadata service is
http://169.254.169.254/latest/meta-data/

Note: If no IAM role is attached to the instance then you will get “404 – Not Found” error in the responce.

Leave a Reply