How to Get the Instance Profile Attached to an AWS EC2


If you need to get the IAM Role information from the attached EC2 role directly, you can do the following:

IAM_ROLE=$(curl -s 169.254.169.254/latest/meta-data/iam/info | \
  jq -r '.InstanceProfileArn' | cut -d'/' -f2)