def _find_project_execution_role()

in migration/bring-your-own-role/byor.py [0:0]


def _find_project_execution_role(args, iam_client, datazone):
    tooling_env_id = datazone.list_environments(
        domainIdentifier=args.domain_id,
        projectIdentifier=args.project_id,
        name="Tooling"
    )['items'][0]['id']
    tooling_env_resources = datazone.get_environment(
        domainIdentifier=args.domain_id,
        identifier=tooling_env_id
    )['provisionedResources']
    try:
        user_role = [resource for resource in tooling_env_resources if resource['name'] == 'userRoleArn'][0]
        role_arn = user_role['value']
    except:
        raise Exception(f"Could not find execution IAM role from Project {args.project_id} tooling environment")
    try:
        return iam_client.get_role(
            RoleName=_get_role_name_from_arn(role_arn),
        )
    except:
        raise Exception(f"Could not find execution IAM role {role_arn} from IAM, please make sure the role exists")