def get_ou_name_id()

in AccountCreationLambda.py [0:0]


def get_ou_name_id(event, root_id, organization_unit_name):
    """ Gets OU Name Identifier """
    ou_client = get_client('organizations')
    list_of_ou_ids = []
    list_of_OU_names = []
    ou_name_to_id = {}

    list_of_ou_ids = get_ous(root_id)

    for j in range(len(list_of_ou_ids)):
        response = ou_client.describe_organizational_unit(OrganizationalUnitId=list_of_ou_ids[j])
        OU_name = response['OrganizationalUnit']['Name']
        list_of_OU_names.append(OU_name)

    if organization_unit_name not in list_of_OU_names:
        print(
            "The provided Organization Unit Name doesnt exist. \
              Creating an OU named: {}".format(organization_unit_name))
        try:
            ou_creation_response = ou_client.create_organizational_unit(
                                    ParentId=root_id, Name=organization_unit_name
                                   )
            for k, v in ou_creation_response.items():
                for k1, v1 in v.items():
                    if k1 == 'Name':
                        organization_unit_name = v1
                    if k1 == 'Id':
                        organization_unit_id = v1
        except botocore.exceptions.ClientError as e:
            print("Error in creating the OU: {}".format(e))
            respond_cloudformation(event, "FAILED",
                 {"Message": "Could not list out AWS Organization OUs. Account creation Aborted."})

    else:
        for i in range(len(list_of_OU_names)):
            ou_name_to_id[list_of_OU_names[i]] = list_of_ou_ids[i]
        organization_unit_id = ou_name_to_id[organization_unit_name]

    return (organization_unit_name, organization_unit_id)