Skip to content

Commit 6bb3569

Browse files
committed
build: Making use of CLIAuthentication class to fetch the workspace. This is a new change from AML SDK. Requires that you have ran az login on the machine before you run the scripts under aml_service folder
1 parent 3fb7466 commit 6bb3569

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

aml_service/00-WorkSpace.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
POSSIBILITY OF SUCH DAMAGE.
2525
"""
2626
from azureml.core import Workspace
27-
import os, json
27+
import os, json, sys
2828
import azureml.core
29+
from azureml.core.authentication import AzureCliAuthentication
2930

3031
print("SDK Version:", azureml.core.VERSION)
3132
# print('current dir is ' +os.curdir)
@@ -36,12 +37,15 @@
3637
resource_group = config["resource_group"]
3738
subscription_id = config["subscription_id"]
3839
location = config["location"]
39-
# location = 'southcentralus'
40+
41+
cli_auth = AzureCliAuthentication()
42+
4043
try:
4144
ws = Workspace.get(
4245
name=workspace_name,
4346
subscription_id=subscription_id,
4447
resource_group=resource_group,
48+
auth=cli_auth
4549
)
4650

4751
except:
@@ -53,6 +57,8 @@
5357
resource_group=resource_group,
5458
# create_resource_group=True,
5559
location=location,
60+
auth=cli_auth
61+
5662
)
5763

5864
# print Workspace details

aml_service/10-TrainOnLocal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
from azureml.core import Experiment
3030
from azureml.core import ScriptRunConfig
3131
import json
32+
from azureml.core.authentication import AzureCliAuthentication
33+
cli_auth = AzureCliAuthentication()
3234

3335
# Get workspace
34-
ws = Workspace.from_config()
36+
ws = Workspace.from_config(auth=cli_auth)
3537

3638
# Attach Experiment
3739
experiment_name = "devops-ai-demo"

aml_service/15-EvaluateModel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
from azureml.core.model import Model
3030
import azureml.core
3131
from azureml.core import Run
32-
32+
from azureml.core.authentication import AzureCliAuthentication
33+
cli_auth = AzureCliAuthentication()
3334

3435
# Get workspace
35-
ws = Workspace.from_config()
36+
ws = Workspace.from_config(auth=cli_auth)
3637

3738
# Paramaterize the matrics on which the models should be compared
3839

aml_service/20-RegisterModel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
from azureml.core.model import Model
3131

3232
from azureml.core.runconfig import RunConfiguration
33+
from azureml.core.authentication import AzureCliAuthentication
34+
cli_auth = AzureCliAuthentication()
3335

3436
# Get workspace
35-
ws = Workspace.from_config()
37+
ws = Workspace.from_config(auth=cli_auth)
3638

3739
# Get the latest evaluation result
3840
try:

aml_service/30-CreateScoringImage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
from azureml.core import Workspace
2828
from azureml.core.image import ContainerImage, Image
2929
from azureml.core.model import Model
30+
from azureml.core.authentication import AzureCliAuthentication
31+
cli_auth = AzureCliAuthentication()
3032

3133
# Get workspace
32-
ws = Workspace.from_config()
34+
ws = Workspace.from_config(auth=cli_auth)
3335

3436
# Get the latest model details
3537

0 commit comments

Comments
 (0)