你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

创建数据存储

适用范围:Azure CLI ml 扩展 v2(最新版)Python SDK azure-ai-ml v2(最新版)

本文介绍如何通过 Azure 机器学习数据存储连接到 Azure 数据存储服务。

先决条件

注意

Azure 机器学习数据存储不会创建基础存储帐户资源。 相反,它们链接现有存储帐户以供 Azure 机器学习使用。 这不需要 Azure 机器学习数据存储。 如果有权访问基础数据,可以直接使用存储 URI。

创建 Azure Blob 数据存储

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)

创建 Azure Data Lake Gen2 数据存储

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

ml_client = MLClient.from_config()

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

ml_client.create_or_update(store)

创建 Azure 文件存储数据存储

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

ml_client = MLClient.from_config()

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= "XXXxxxXXXxXXXXxxXXXXXxXXXXXxXxxXxXXXxXXXxXXxxxXXxxXXXxXxXXXxxXxxXXXXxxxxxXXxxxxxxXXXxXXX"
    ),
)

ml_client.create_or_update(store)

创建 Azure Data Lake Gen1 数据存储

from azure.ai.ml.entities import AzureDataLakeGen1Datastore
from azure.ai.ml import MLClient

ml_client = MLClient.from_config()

store = AzureDataLakeGen1Datastore(
    name="",
    store_name="",
    description="",
)

ml_client.create_or_update(store)

创建 OneLake (Microsoft Fabric) 数据存储(预览版)

本部分介绍了用于创建 OneLake 数据存储的各种选项。 OneLake 数据存储是 Microsoft Fabric 的一部分。 目前,Azure 机器学习支持连接到 Microsoft Fabric Lakehouse 项目,包括文件夹/文件和 Amazon S3 快捷方式。 有关湖屋的详细信息,请访问什么是 Microsoft Fabric 中的湖屋

OneLake 数据存储创建需要

  • 端点
  • Fabric 工作区名称或 GUID
  • 项目名称或 GUID

来自你的 Microsoft Fabric 实例的信息。 这三个屏幕截图描述了从 Microsoft Fabric 实例检索这些必需的信息资源:

OneLake 工作区名称

在你的 Microsoft Fabric 实例中,你可以找到工作区信息,如以下屏幕截图所示。 你可以使用 GUID 值或“友好名称”来创建 Azure 机器学习 OneLake 数据存储。

Screenshot that shows Fabric Workspace details in Microsoft Fabric UI.

OneLake 终结点

以下屏幕截图显示了如何在 Microsoft Fabric 实例中找到终结点信息:

Screenshot that shows Fabric endpoint details in Microsoft Fabric UI.

OneLake 项目名称

以下屏幕截图显示了如何在 Microsoft Fabric 实例中找到项目信息。 此屏幕截图还显示了如何使用 GUID 值或“易记名称”来创建 Azure 机器学习 OneLake 数据存储:

Screenshot showing how to get Fabric LH artifact details in Microsoft Fabric UI.

创建 OneLake 数据存储

from azure.ai.ml.entities import OneLakeDatastore, OneLakeArtifact
from azure.ai.ml import MLClient

ml_client = MLClient.from_config()

store = OneLakeDatastore(
    name="onelake_example_id",
    description="Datastore pointing to an Microsoft fabric artifact.",
    one_lake_workspace_name="AzureML_Sample_OneLakeWS",
    endpoint="msit-onelake.dfs.fabric.microsoft.com"
    artifact = OneLakeArtifact(
        name="AzML_Sample_LH",
        type="lake_house"
    )
)

ml_client.create_or_update(store)

后续步骤