创建数据存储

适用于:Azure CLI ml 扩展 v2(当前版本)Python SDK azure-ai-ml v2(当前版本)

本文介绍如何使用 Azure Machine Learning 的数据存储来连接到 Azure 数据存储服务。

先决条件

  • Azure订阅。 如果没有Azure订阅,请在开始前创建试用版。 尝试试用版订阅
  • Python 3.10 或更高版本。
  • 适用于 Python 的 Azure Machine Learning SDK
  • Machine Learning工作区。

注意事项

机器学习数据存储不会创建基础存储帐户资源。 相反,它们链接了用于机器学习使用的现有存储帐户。 每个数据存储类型都是独立创建的。 本文中各节的顺序并不表示所需的步骤序列。

创建Azure Blob 数据存储

from azure.ai.ml.entities import AzureBlobDatastore
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential

ml_client = MLClient.from_config(credential=DefaultAzureCredential())

store = AzureBlobDatastore(
    name="",
    description="",
    account_name="",
    container_name=""
)

ml_client.create_or_update(store)

创建Azure Data Lake Storage Gen2数据存储

from azure.ai.ml.entities import AzureDataLakeGen2Datastore
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential

ml_client = MLClient.from_config(credential=DefaultAzureCredential())

store = AzureDataLakeGen2Datastore(
    name="",
    description="",
    account_name="",
    filesystem=""
)

ml_client.create_or_update(store)

创建Azure Files数据存储

from azure.ai.ml.entities import AzureFileDatastore
from azure.ai.ml.entities import AccountKeyConfiguration
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential

ml_client = MLClient.from_config(credential=DefaultAzureCredential())

store = AzureFileDatastore(
    name="file_example",
    description="Datastore pointing to an Azure File Share.",
    account_name="mytestfilestore",
    file_share_name="my-share",
    credentials=AccountKeyConfiguration(
        account_key= "aaaaaaaa-0b0b-1c1c-2d2d-333333333333"
    ),
)

ml_client.create_or_update(store)

后续步骤