Using boto3
I have many groups, just over 75 of them. I would like to find the users and the in each group and the last time their password was used. (the 'PasswordLastUsed' key - I am not sure if I can use it with get_group. I see it in the docs but it does not work.
response = iam.get_group(
GroupName='groupA'
#GroupName=['groupA','groupB','groupC']
)
print(response['Group']['GroupName'])
for user in response['Users']:
print("UserName: {0}\nArn: {1}\n"
.format(user['UserName'], user['Arn']))
I would like to know how i can iterate through each group so it looks like this:
(the above code will do for 1 group and look like below, I just would like to do >1 group at a time.
groupA
UserName: mickey
Arn: hkhjjklljlj
UserName: donald
Arn: hkhjjklljlj
groupB:
UserName: goofy
Arn: hkhjjfgkgfk
UserName: daffy
Arn: lkjkljkoj
etc...
CodePudding user response:
First you have to use list_groups to get all groups, and then you can query for details of each group:
response = iam.list_groups()
for group in response['Groups']:
group_details = iam.get_group(GroupName=group['GroupName'])
print(group['GroupName'])
for user in group_details['Users']:
print(" - ", user['UserName'])