def get_role()

in sagemaker_studio_image_build/cli.py [0:0]


def get_role(args):
    if args.role:
        return args.role

    try:
        # The SDK logs a warning for not having pandas and this is the only way to suppress it.
        # https://github.com/aws/sagemaker-python-sdk/issues/1696
        logging.basicConfig(level=logging.CRITICAL)
        import sagemaker

        logging.basicConfig(level=logging.INFO)
        # arn:aws:iam::$account_id:role/$path/$name -> $path/$name
        return "/".join(sagemaker.get_execution_role().split(":")[-1].split("/")[1:])
    except ValueError as e:
        raise ValueError(
            "Unable to determine execution role. Please provide via the --role argument",
            e,
        )