-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam_role_trust_policies.py
More file actions
54 lines (36 loc) · 1.23 KB
/
iam_role_trust_policies.py
File metadata and controls
54 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import json
import boto3
from utils.session import get_session
from utils.regions import get_all_regions
from utils.json_encoder import json_encoder
from utils.json_writer import json_writer
from utils.json_printer import json_printer
def get_role_names(client):
paginator = client.get_paginator('list_roles')
page_iterator = paginator.paginate(MaxItems=200)
for page in page_iterator:
for role in page['Roles']:
yield role['RoleName']
def get_role_details(client, role_name):
role = client.get_role(RoleName=role_name)['Role']
return role
def main():
session = get_session()
all_data = {}
client = session.client('iam')
for role_name in get_role_names(client):
print('RoleName: %s' % (role_name,))
roles = []
try:
role_details = get_role_details(client, role_name)
except Exception as e:
msg = 'Failed to retrieve role for %s. Error: "%s"'
args = (role_name, e)
print(msg % args)
all_data[role_name] = role_details
os.makedirs('output', exist_ok=True)
json_writer('output/role-details.json', all_data)
json_printer(all_data)
if __name__ == '__main__':
main()