The Device login routine used by the AML Python SDK uses the default tenant associated with the login account. This can create issues when working with AML instances in other tenants.
Use the simple login if your AML workspace is within your default tenant. Use the alternative login to force login into a specific tenant.
This uses the config.json file in the directory structure of the local system. For an AML-provisioned compute VM, this file is located at the root /config.json. If you get an error here as a result of logging into the wrong tenant, use the alternative below.
from azureml.core import Workspace
ws.Workspace.from_config()
When working with multiple tenants, use the following to avoid difficulty as a result of your default login tenant being prioritised. This code explicitly specifies the tenant to log in to, and does not use the config.json file.
from azureml.core.authentication import InteractiveLoginAuthentication
Set the workspace parameters:
- Find your tenant id by clicking your name or profile photo in the top right corner of the Azure portal, then select
switch directory
- Find the remaining parameters in the
config.json
file associated with your AML workspace (downloadable from the portal)
mytenant = "<your tenant id>"
mysub = "<your subscription id>"
myrg = "<your resource group>"
wsname = "<your workspacename>"
Trigger the interactive login
auth = InteractiveLoginAuthentication(force=True, tenant_id=mytenant)
use the get()
method instead of the from_config()
method.
ws = Workspace.get(wsname, auth, subscription_id=mysub, resource_group=myrg)
- Find the configuration variables for your AML workspace in your config.json file, downloadable from the portal
- Interactive Login Authentication
- Workpace.get() method