데이터 저장소 관리를 SDK v2로 업그레이드

Azure Machine Learning 데이터 저장소는 Azure의 데이터 스토리지에 대한 연결 정보를 안전하게 유지하므로 스크립트에서 코딩할 필요가 없습니다. V2 데이터 저장소 개념은 V1과 비교하여 대부분 변경되지 않았습니다. 차이점은 Azure Machine Learning 데이터 저장소를 통해 SQL과 유사한 데이터 원본을 지원하지 않는다는 것입니다. Azure Machine Learning 데이터 가져오기 및 내보내기 기능을 통해 SQL과 유사한 데이터 원본을 지원합니다.

이 문서에서는 SDK v1과 SDK v2의 시나리오를 비교합니다.

account_key를 통해 Azure Blob 컨테이너에서 데이터 저장소 만들기

  • SDK v1

    blob_datastore_name='azblobsdk' # Name of the datastore to workspace
    container_name=os.getenv("BLOB_CONTAINER", "<my-container-name>") # Name of Azure blob container
    account_name=os.getenv("BLOB_ACCOUNTNAME", "<my-account-name>") # Storage account name
    account_key=os.getenv("BLOB_ACCOUNT_KEY", "<my-account-key>") # Storage account access key
    
    blob_datastore = Datastore.register_azure_blob_container(workspace=ws, 
                                                             datastore_name=blob_datastore_name, 
                                                             container_name=container_name, 
                                                             account_name=account_name,
                                                             account_key=account_key)
    
  • SDK v2

    from azure.ai.ml.entities import AzureBlobDatastore
    from azure.ai.ml import MLClient
    
    ml_client = MLClient.from_config()
    
    store = AzureBlobDatastore(
        name="blob-protocol-example",
        description="Datastore pointing to a blob container using wasbs protocol.",
        account_name="mytestblobstore",
        container_name="data-container",
        protocol="wasbs",
        credentials={
            "account_key": "XXXxxxXXXxXXXXxxXXXXXxXXXXXxXxxXxXXXxXXXxXXxxxXXxxXXXxXxXXXxxXxxXXXXxxxxxXXxxxxxxXXXxXXX"
        },
    )
    
    ml_client.create_or_update(store)
    

sas_token을 통해 Azure Blob 컨테이너에서 데이터 저장소 만들기

  • SDK v1

    blob_datastore_name='azblobsdk' # Name of the datastore to workspace
    container_name=os.getenv("BLOB_CONTAINER", "<my-container-name>") # Name of Azure blob container
    sas_token=os.getenv("BLOB_SAS_TOKEN", "<my-sas-token>") # Sas token
    
    blob_datastore = Datastore.register_azure_blob_container(workspace=ws, 
                                                             datastore_name=blob_datastore_name, 
                                                             container_name=container_name, 
                                                             sas_token=sas_token)
    
  • SDK v2

    from azure.ai.ml.entities import AzureBlobDatastore
    from azure.ai.ml import MLClient
    
    ml_client = MLClient.from_config()
    
    store = AzureBlobDatastore(
        name="blob-sas-example",
        description="Datastore pointing to a blob container using SAS token.",
        account_name="mytestblobstore",
        container_name="data-container",
        credentials=SasTokenCredentials(
            sas_token= "?xx=XXXX-XX-XX&xx=xxxx&xxx=xxx&xx=xxxxxxxxxxx&xx=XXXX-XX-XXXXX:XX:XXX&xx=XXXX-XX-XXXXX:XX:XXX&xxx=xxxxx&xxx=XXxXXXxxxxxXXXXXXXxXxxxXXXXXxxXXXXXxXXXXxXXXxXXxXX"
        ),
    )
    
    ml_client.create_or_update(store)
    

ID 기반 인증을 통해 Azure Blob 컨테이너에서 데이터 저장소 만들기

  • SDK v1
blob_datastore = Datastore.register_azure_blob_container(workspace=ws,
                                                      datastore_name='credentialless_blob',
                                                      container_name='my_container_name',
                                                      account_name='my_account_name')

  • SDK v2

    from azure.ai.ml.entities import AzureBlobDatastore
    from azure.ai.ml import MLClient
    
    ml_client = MLClient.from_config()
    
    store = AzureBlobDatastore(
        name="",
        description="",
        account_name="",
        container_name=""
    )
    
    ml_client.create_or_update(store)
    

작업 영역에서 데이터 저장소 가져오기

  • SDK v1

    # Get a named datastore from the current workspace
    datastore = Datastore.get(ws, datastore_name='your datastore name')
    
    # List all datastores registered in the current workspace
    datastores = ws.datastores
    for name, datastore in datastores.items():
        print(name, datastore.datastore_type)
    
  • SDK v2

    from azure.ai.ml import MLClient
    from azure.identity import DefaultAzureCredential
    
    #Enter details of your Azure Machine Learning workspace
    subscription_id = '<SUBSCRIPTION_ID>'
    resource_group = '<RESOURCE_GROUP>'
    workspace_name = '<AZUREML_WORKSPACE_NAME>'
    
    ml_client = MLClient(credential=DefaultAzureCredential(),
                         subscription_id=subscription_id, 
                         resource_group_name=resource_group)
    
    datastore = ml_client.datastores.get(name='your datastore name')
    

SDK v1 및 SDK v2의 주요 기능 매핑

SDK v1의 스토리지 형식 SDK v2의 스토리지 형식
azureml_blob_datastore azureml_blob_datastore
azureml_data_lake_gen1_datastore azureml_data_lake_gen1_datastore
azureml_data_lake_gen2_datastore azureml_data_lake_gen2_datastore
azuremlml_sql_database_datastore 가져오기 및 내보내기 기능을 통해 지원됩니다.
azuremlml_my_sql_datastore 가져오기 및 내보내기 기능을 통해 지원됩니다.
azuremlml_postgre_sql_datastore 가져오기 및 내보내기 기능을 통해 지원됩니다.

다음 단계

자세한 내용은 다음을 참조하세요.