NEW: dump aws organization tree

This commit is contained in:
xpk 2022-05-13 23:24:11 +08:00
parent 47a3f4bee0
commit ca8cd15ffb
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
1 changed files with 33 additions and 0 deletions

33
aws/aws-org-dump.py Normal file
View File

@ -0,0 +1,33 @@
import boto3
def recurseChildren(ouid, level):
children = client.list_organizational_units_for_parent(ParentId=ouid).get('OrganizationalUnits')
if len(children) == 0:
childAccounts = getChildAccunts(ouid)
for c in childAccounts:
print('.' * level, c[0], c[1])
return
else:
for c in children:
print('.' * level, c.get('Name'), c.get('Id'))
recurseChildren(c.get('Id'), level + 1)
def getChildAccunts(ouid):
childAccounts = client.list_accounts_for_parent(ParentId=ouid).get('Accounts')
reducedList = []
for a in childAccounts:
tempList = [a.get('Name'), a.get('Id')]
reducedList.append(tempList)
return reducedList
client = boto3.client('organizations')
response = client.list_roots()
for r in response.get('Roots'):
rootId = r.get('Id')
recurseChildren(rootId, 1)