如何将 AMLS 连接到 ADLS Gen 2?
How to connect AMLS to ADLS Gen 2?
我想在我的 Azure 机器学习工作区 (azureml-core==1.12.0
) 中注册来自 ADLS Gen2 的数据集。鉴于 Python SDK documentation 中 .register_azure_data_lake_gen2()
不需要服务主体信息,我成功使用以下代码将 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'))
我收到一个错误
Cannot load any data from the specified path. Make sure the path is accessible and contains data.
ScriptExecutionException
was caused by StreamAccessException
.
StreamAccessException was caused by AuthenticationException.
'AdlsGen2-ReadHeaders'
for '[REDACTED]' on storage failed with status code 'Forbidden' (This request is not authorized to perform this operation using this permission.), client request ID <CLIENT_REQUEST_ID>, request ID <REQUEST_ID>. Error message: [REDACTED]
| session_id=<SESSION_ID>
我是否需要启用服务主体才能使其正常工作?使用 ML Studio UI,似乎甚至需要服务主体来注册数据存储。
我注意到的另一个问题是 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.you 需要注册您的应用程序并授予服务主体存储 Blob 数据 Reader 访问权限.
2.try 此代码:
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())
结果:
我想在我的 Azure 机器学习工作区 (azureml-core==1.12.0
) 中注册来自 ADLS Gen2 的数据集。鉴于 Python SDK documentation 中 .register_azure_data_lake_gen2()
不需要服务主体信息,我成功使用以下代码将 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'))
我收到一个错误
Cannot load any data from the specified path. Make sure the path is accessible and contains data.
ScriptExecutionException
was caused byStreamAccessException
. StreamAccessException was caused by AuthenticationException.'AdlsGen2-ReadHeaders'
for '[REDACTED]' on storage failed with status code 'Forbidden' (This request is not authorized to perform this operation using this permission.), client request ID <CLIENT_REQUEST_ID>, request ID <REQUEST_ID>. Error message: [REDACTED] | session_id=<SESSION_ID>
我是否需要启用服务主体才能使其正常工作?使用 ML Studio UI,似乎甚至需要服务主体来注册数据存储。
我注意到的另一个问题是 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.you 需要注册您的应用程序并授予服务主体存储 Blob 数据 Reader 访问权限.
2.try 此代码:
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())
结果: