Amazon Web Services (AWS) - List IAM Profiles using the AWS CLI

by
Jeremy Canfield |
Updated: April 15 2024
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
- An IAM Policy allows certain actions (such create) on certain resources (such as EC2)
- An IAM User is typically a users account (such as john.doe) that contains an IAM Identity-Based Policy that allows certain actions (such as list) on certain resources (such S3)
- An IAM Role contains an IAM Policy that allows certain actions (such create) on certain resources (such as EC2). Let's say the Identity-Based Policy attached to john.doe does NOT allow "create S3"
- The Role that allows "create S3" could be attached to john.doe - or, john.doe could Assume the Role:
- Often, a Role will have two Policies:
The aws iam list-instance-profiles command can be used to list all of the IAM profiles.
aws iam list-instance-profiles
And here is an example of how to limit the output using the --query option.
aws iam list-instance-profiles --query 'InstanceProfiles[?InstanceProfileName==`AmazonSSMRoleForInstancesQuickSetup`]'
Something like this should be returned.
{
"InstanceProfiles": [
{
"Path": "/",
"InstanceProfileName": "my-foo-profile",
"InstanceProfileId": "ABCDEFG123456789",
"Arn": "arn:aws:iam::123456789012:instance-profile/my-foo-profile",
"CreateDate": "2021-09-09T13:29:20+00:00",
"Roles": []
},
{
"Path": "/",
"InstanceProfileName": "my-bar-profile",
"InstanceProfileId": "123456789ABCDEFG",
"Arn": "arn:aws:iam::123456789012:instance-profile/my-bar-profile",
"CreateDate": "2021-09-09T13:29:20+00:00",
"Roles": []
}
]
}
Did you find this article helpful?
If so, consider buying me a coffee over at