in src/python-sdk-v2/create_compute_instance.py [0:0]
def connect_to_aml(args):
"""Connect to Azure ML workspace using provided cli arguments."""
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 workspace
try:
# ml_client to connect using local config.json
ml_client = MLClient.from_config(credential, path='config.json')
except Exception as ex:
print(
"Could not find config.json, using config.yaml refs to Azure ML workspace instead."
)
# tries to connect using cli args if provided else using config.yaml
ml_client = MLClient(
subscription_id=args.subscription_id,
resource_group_name=args.resource_group,
workspace_name=args.workspace_name,
credential=credential,
)
return ml_client