Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the list of policies assigned to a user using boto3 for an aws profile?

I am still in the learning phase of boto3 and I can't seem to figure out the basics as to get the list of policies assigned to a user using boto3 for an aws profile?

For example:

>> import boto3
>> client=boto3.client('iam')
>> client.get_user()

Here, client.get_user() doesn't give me the policy attribute.

Thanks

like image 299
user3399273 Avatar asked Feb 10 '16 22:02

user3399273


People also ask

How do I see what roles are assigned to AWS?

Under the AWS Management Console section, choose the role you want to view. On the Selected role page, under Manage users and groups for this role, you can view the users and groups assigned to the role.

How do I get an AWS policy Arn?

For more information about ARNs, go to Amazon Resource Names (ARNs) in the Amazon Web Services General Reference . The path to the policy. For more information about paths, see IAM identifiers in the IAM User Guide . The identifier for the version of the policy that is set as the default version.

What is the difference between Boto3 client and Boto3 resource?

00:00 Boto3's primary function is to make AWS API calls for you. It extracts these APIs in two main ways: clients and resources. Clients give you low-level service access, while resources provide an object-oriented way of working with these services.


1 Answers

I know this is an old question, but what you want is:

For inline policies:

inline_user_policies = client.list_user_policies(UserName=user_name)

For managed policies:

managed_user_policies = client.list_attached_user_policies(UserName=user_name)
like image 190
Justin Blau Avatar answered Nov 15 '22 07:11

Justin Blau