如何将AMLS连接到第二代ADLS?

问题描述

我想在我的Azure机器学习工作区(azureml-core==1.12.0)中注册来自ADLS Gen2的数据集。鉴于.register_azure_data_lake_gen2()的Python SDK documentation中不需要服务主体信息,我成功使用以下代码将ADLS gen2注册为数据存储:

from azureml.core import Datastore

adlsgen2_datastore_name = os.environ['adlsgen2_datastore_name']
account_name=os.environ['account_name'] # ADLS Gen2 account name
file_system=os.environ['filesystem']

adlsgen2_datastore = Datastore.register_azure_data_lake_gen2(
    workspace=ws,datastore_name=adlsgen2_datastore_name,account_name=account_name,filesystem=file_system
)

但是,当我尝试注册数据集时,使用

from azureml.core import Dataset
adls_ds = Datastore.get(ws,datastore_name=adlsgen2_datastore_name)
data = Dataset.Tabular.from_delimited_files((adls_ds,'folder/data.csv'))

我遇到错误

无法从指定路径加载任何数据。确保路径可访问并且包含数据。 ScriptExecutionException是由StreamAccessException引起的。 StreamAccessException是由AuthenticationException引起的。 'AdlsGen2-ReadHeaders'上存储的“ [已编辑]”失败,状态码为“禁止”(此请求无权使用此权限进行此操作。),客户端请求ID为,请求ID为错误消息:[已删除] | session_id =

我是否需要启用服务主体才能使其正常工作?使用ML Studio用户界面,似乎即使注册数据存储也需要服务主体。

我注意到的另一个问题是AMLS试图在此处访问数据集: https://adls_gen2_account_name.**dfs**.core.windows.net/container/folder/data.csv,而ADLS Gen2中的实际URI为:https://adls_gen2_account_name.**blob**.core.windows.net/container/folder/data.csv

解决方法

根据此documentation,您需要启用服务主体。

1。您需要注册您的应用程序并授予 Storage Blob Data Reader访问权限

enter image description here

2。尝试以下代码:

adlsgen2_datastore = Datastore.register_azure_data_lake_gen2(workspace=ws,datastore_name=adlsgen2_datastore_name,account_name=account_name,filesystem=file_system,tenant_id=tenant_id,client_id=client_id,client_secret=client_secret
                                                             )

adls_ds = Datastore.get(ws,datastore_name=adlsgen2_datastore_name)
dataset = Dataset.Tabular.from_delimited_files((adls_ds,'sample.csv'))
print(dataset.to_pandas_dataframe())

结果:

enter image description here