Skip to content

Commit 7b3dafe

Browse files
authored
Merge pull request #100326 from Blackmist/verbatim
updating for auth
2 parents c06a8af + a94962c commit 7b3dafe

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

articles/machine-learning/how-to-deploy-local-container-notebook-vm.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,33 @@ An example notebook that demonstrates local deployments is included on your comp
5858

5959
To submit sample data to the running service, use the following code. Replace the value of `service_url` with the URL of from the previous step:
6060

61+
> [!NOTE]
62+
> When authenticating to a deployment on the compute instance, the authentication is made using Azure Active Directory. The call to `interactive_auth.get_authentication_header()` in the example code authenticates you using AAD, and returns a header that can then be used to authenticate to the service on the compute instance. For more information, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md#interactive-authentication).
63+
>
64+
> When authenticating to a deployment on Azure Kubernetes Service or Azure Container Instances, a different authentication method is used. For more information on, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md#web-service-authentication).
65+
6166
```python
6267
import requests
6368
import json
69+
from azureml.core.authentication import InteractiveLoginAuthentication
70+
71+
# Get a token to authenticate to the compute instance from remote
72+
interactive_auth = InteractiveLoginAuthentication()
73+
auth_header = interactive_auth.get_authentication_header()
74+
75+
# Create and submit a request using the auth header
76+
headers = auth_header
77+
# Add content type header
78+
headers.update({'Content-Type':'application/json'})
79+
80+
# Sample data to send to the service
6481
test_sample = json.dumps({'data': [
6582
[1,2,3,4,5,6,7,8,9,10],
6683
[10,9,8,7,6,5,4,3,2,1]
6784
]})
6885
test_sample = bytes(test_sample,encoding = 'utf8')
69-
access_token = "your bearer token"
70-
headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + access_token}
86+
87+
# Replace with the URL for your compute instance, as determined from the previous section
7188
service_url = "https://vm-name-6789.northcentralus.notebooks.azureml.net/score"
7289
# for a compute instance, the url would be https://vm-name-6789.northcentralus.instances.azureml.net/score
7390
resp = requests.post(service_url, test_sample, headers=headers)

0 commit comments

Comments
 (0)