You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Databricks Notebook触发Azure Machine Learning Studio Notebook运行?

从Databricks Notebook触发Azure ML Studio Notebook的最优方案

核心方案:使用Azure ML Python SDK直接提交Notebook作业

这是Azure原生集成的编程方式,无需额外中间服务,灵活性与可控性最强。

步骤1:在Databricks Notebook中安装Azure ML SDK

执行以下命令安装适配的Azure ML SDK版本:

%pip install azure-ai-ml

步骤2:配置身份验证(推荐使用服务主体)

通过Databricks密钥管理存储Azure服务主体凭据(避免硬编码),初始化MLClient连接到目标Azure ML工作区:

from azure.ai.ml import MLClient
from azure.identity import ClientSecretCredential

# 从Databricks密钥作用域读取凭据
tenant_id = dbutils.secrets.get(scope="your-secret-scope", key="tenant-id")
client_id = dbutils.secrets.get(scope="your-secret-scope", key="client-id")
client_secret = dbutils.secrets.get(scope="your-secret-scope", key="client-secret")

# 填写Azure ML工作区基础信息
subscription_id = "your-subscription-id"
resource_group = "your-resource-group-name"
workspace_name = "your-aml-workspace-name"

# 初始化MLClient实例
credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
ml_client = MLClient(credential, subscription_id, resource_group, workspace_name)

步骤3:提交Azure ML Notebook作业

定义作业参数,指定目标Notebook路径、计算集群和运行环境,提交作业并获取反馈:

from azure.ai.ml.entities import NotebookJob

# 配置Notebook作业参数
notebook_job = NotebookJob(
    name="aml-notebook-triggered-by-databricks",
    notebook_path="/Users/your-email@domain.com/target-notebook.ipynb",  # Azure ML工作区中Notebook的完整路径
    compute="your-aml-compute-cluster-name",  # 已创建的Azure ML计算集群名称
    environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",  # 匹配Notebook依赖的环境,支持自定义
)

# 提交作业并输出作业ID
submitted_job = ml_client.jobs.create_or_update(notebook_job)
print(f"作业提交成功,作业ID: {submitted_job.id}")

可选方案:通过Azure Logic Apps触发(低代码场景适用)

若无需深度编程控制,可通过以下流程实现:

  1. 在Databricks Notebook中调用Logic Apps的HTTP触发器
  2. Logic Apps通过Azure ML API提交Notebook作业
    该方案多一层中间服务,可控性弱于SDK直接调用。

关键注意事项

  • 确保服务主体拥有Azure ML工作区的Contributor或Job Submitter角色权限
  • Azure ML中的Notebook路径需准确,可在Azure ML Studio的Notebook详情页查看完整路径
  • 运行环境需匹配Notebook的依赖包,避免执行时出现依赖缺失报错

内容的提问来源于stack exchange,提问作者Sadman Saadat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:36:10