I fetched the organization list and the response includes the organization ids and the organization type. I want to fetch the organization names because my logic needs to look for a particular organization. How can i enhance the code to do that?
def get_ou_ids(parent_id): list_of_OU_ids = [] client = boto3.client('organizations')
paginator = client.get_paginator('list_children')
iterator = paginator.paginate(
ParentId=parent_id,
ChildType='ORGANIZATIONAL_UNIT'
)
for page in iterator:
print(page['Children'])
for ou in page['Children']:
list_of_OU_ids.append(ou['Id'])
list_of_OU_ids.extend(get_ou_ids(ou['Id']))
return list_of_OU_ids
Output:-
[{'Id': 'ou-kfg9-68vbrelq', 'Type': 'ORGANIZATIONAL_UNIT'}, {'Id': 'ou-kfg9-7s4296qn', 'Type': 'ORGANIZATIONAL_UNIT'}, {'Id': 'ou-kfg9-tohoeosn', 'Type': 'ORGANIZATIONAL_UNIT'}, {'Id': 'ou-kfg9-39u8reeb', 'Type': 'ORGANIZATIONAL_UNIT'}, {'Id': 'ou-kfg9-9fxflop7', 'Type': 'ORGANIZATIONAL_UNIT'}]
['ou-kfg9-jtd17hu3', 'ou-kfg9-r1zyqdhf', 'ou-kfg9-68vbrelq', 'ou-kfg9-7s4296qn', 'ou-kfg9-tohoeosn', 'ou-kfg9-39u8reeb', 'ou-kfg9-9fxflop7']
parent_Id in get_ou_name_id : r-kfg9