如何在管道作业中访问私有blob容器- Azure SDKv 2?

w8rqjzmb  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(145)

我从官方文档中获取了这个例子(你在下面看到的那个)。

  1. from azure.ai.ml import command, Input, MLClient, UserIdentityConfiguration, ManagedIdentityConfiguration
  2. from azure.ai.ml.entities import Data
  3. from azure.ai.ml.constants import AssetTypes, InputOutputModes
  4. from azure.identity import DefaultAzureCredential
  5. # Set your subscription, resource group and workspace name:
  6. subscription_id = "<SUBSCRIPTION_ID>"
  7. resource_group = "<RESOURCE_GROUP>"
  8. workspace = "<AML_WORKSPACE_NAME>"
  9. # connect to the AzureML workspace
  10. ml_client = MLClient(
  11. DefaultAzureCredential(), subscription_id, resource_group, workspace
  12. )
  13. # ==============================================================
  14. # You can set the identity you want to use in a job to access the data. Options include:
  15. # identity = UserIdentityConfiguration() # Use the user's identity
  16. # identity = ManagedIdentityConfiguration() # Use the compute target managed identity
  17. # ==============================================================
  18. # This example accesses public data, so we don't need an identity.
  19. # You also set identity to None if you use a credential-based datastore
  20. identity = None
  21. # Set the input for the job:
  22. inputs = {
  23. "input_data": Input(type=data_type, path=path, mode=mode)
  24. }
  25. # This command job uses the head Linux command to print the first 10 lines of the file
  26. job = command(
  27. command="head ${{inputs.input_data}}",
  28. inputs=inputs,
  29. environment="azureml://registries/azureml/environments/sklearn-1.1/versions/4",
  30. compute="cpu-cluster",
  31. identity=identity,
  32. )
  33. # Submit the command
  34. ml_client.jobs.create_or_update(job)

字符串
上面的代码来自Azure文档。
我有一个例子,其中下面的输入被馈送到管道作业。然而,我的用例要求容器是私有的。
因此,我的问题是容器名称是私有的,所以我不能像上面的教程那样访问它。
我知道我需要分配一些权限,我在运行代码的群集上已经有一个托管标识,它具有以下权限:
1.包括存储blob容器的存储帐户的所有者和参与者。
1.机器学习工作区的所有者和贡献者。
我有一个自定义输入,它看起来像:

  1. Input(
  2. type="uri_folder",
  3. # Here is the problem, cannot access it in a job.
  4. path="wasbs://container_name@storage_account.blob.core.windows.net/",
  5. mode="ro_mount"
  6. ),


为了能够访问作业中私有容器中的数据(如下面的示例输入),我应该做些什么?

23c0lvtd

23c0lvtd1#

问题是我必须将此角色添加到托管身份:

  1. Storage Blob Data Contributor

字符串
(因为我读取和写入存储帐户内的私有Blob)

相关问题