is it possible to use service principal for authentication to access ml_client?

Viewed 129

The documentation https://docs.microsoft.com/en-us/azure/machine-learning/tutorial-pipeline-python-sdk shows that you can use DefaultAzureCredential and InteractiveBrowserCredential for ml_client. is there a way I can use service principal instead?

#code from docs
# Handle to the workspace
from azure.ai.ml import MLClient

# Authentication package
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential

try:
    credential = DefaultAzureCredential()
    # Check if given credential can get token successfully.
    credential.get_token("https://management.azure.com/.default")
except Exception as ex:
    # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
    credential = InteractiveBrowserCredential()

# Get a handle to the workspace
ml_client = MLClient(
    credential=credential,
    subscription_id="<SUBSCRIPTION_ID>",
    resource_group_name="<RESOURCE_GROUP>",
    workspace_name="<AML_WORKSPACE_NAME>",
)
0 Answers
Related