Created
January 7, 2025 00:27
-
-
Save abgoswam/95b4b76af7f19eee9988d1bc3c541f70 to your computer and use it in GitHub Desktop.
AML WS Connection to ACR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from azure.ai.ml import MLClient | |
from azure.ai.ml.entities import WorkspaceConnection | |
from azure.identity import DefaultAzureCredential | |
from azure.ai.ml.entities import UsernamePasswordConfiguration | |
# Enter details of your AML workspace | |
subscription_id = "" | |
resource_group = "" | |
workspace_name = "" | |
# get a handle to the workspace | |
ml_client = MLClient( | |
DefaultAzureCredential(), subscription_id, resource_group, workspace_name | |
) | |
# verify existing connections | |
for conn in ml_client.connections.list(): | |
print(conn) | |
print("==============") | |
###################### if connection exists. QUIT | |
# fetching secrets from env var to secure access, these secrets can be set outside or source code | |
acr_username = "" # fill in e.g. testacr | |
acr_password = "" | |
credentials = UsernamePasswordConfiguration( | |
username=acr_username, password=acr_password | |
) | |
ws_connection = WorkspaceConnection( | |
name="", # fill in e.g. testacr.azurecr.io | |
target="", # fill in e.g. testacr.azurecr.io | |
type="container_registry", | |
credentials=credentials, | |
) | |
ml_client.connections.create_or_update(ws_connection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment