paraluke23 / automl-handson

Notebook for workshop
20 stars 16 forks source link

Workaround for wrong tenant error when calling Workspace.create #1

Open kszicsillag opened 5 years ago

kszicsillag commented 5 years ago

Hi @parasharshah,

I have participated in a Hand-On Lab session of yours in Budapest, Hungary and I have encountered an issue with the device login using an account linked to multiple Azure AD tenants.

I have added a tiny workaround tutorial in the Create Azure ML workspace step of _007.Predictive_Maint_AutoMLADB.dbc. It looks like this (entire cell):

# Import the Workspace class and check the Azure ML SDK version.
from azureml.core import Workspace

# if your account is linked to multiple tenants and device login tries to login into the wrong tenant you can try this
# 0) check if you have sufficient permission in the tenant of the ML workspace to create service principal (https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#required-permissions). 
# If not, you should reach out to your tenant administrator for further assistance.
# 1) create a service principal in the tenant of the ML workspace - https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal
# 2) generate a secret key for the service principal - https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#get-values-for-signing-in
# 3) assign a permission for the service principal to access the ML workspace (e.g. assign owner or contributor role in the resource group)
# 4) comment out the lines below and fill out the necessary parameters

#from azureml.core.authentication import ServicePrincipalAuthentication

#service_principal_auth = ServicePrincipalAuthentication(
#       tenant_id="<directory ID of the right tenant>",
#       service_principal_id="<application ID of the service principal>",
#       service_principal_password="<secret key of the service principal>") 

ws = Workspace.create(name = workspace_name,
                      # auth=service_principal_auth, #uncomment this line if you have to use service principal based authentication
                      subscription_id = subscription_id,
                      resource_group = resource_group, 
                      location = workspace_region,                      
                      exist_ok=True)
ws.get_details()

Feel free to use this in any way you want.

Hope this helps, Gabor

paraluke23 commented 5 years ago

Thank you.