29 lines
743 B
Python
Executable File
29 lines
743 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import boto3
|
|
# import json
|
|
|
|
|
|
def recurseChildren(ouid, level):
|
|
children = client.list_organizational_units_for_parent(ParentId=ouid).get('OrganizationalUnits')
|
|
if len(children) == 0:
|
|
childAccounts = client.list_accounts_for_parent(ParentId=ouid).get('Accounts')
|
|
for c in childAccounts:
|
|
print('.' * level, c.get('Name'), c.get('Id'))
|
|
return
|
|
else:
|
|
for c in children:
|
|
print('.' * level, c.get('Name'), c.get('Id'))
|
|
recurseChildren(c.get('Id'), level + 1)
|
|
|
|
|
|
client = boto3.client('organizations')
|
|
response = client.list_roots()
|
|
|
|
# print(json.dumps(response))
|
|
rootId = response['Roots'][0]['Id']
|
|
print('Root ', rootId)
|
|
|
|
recurseChildren(rootId, 1)
|
|
|