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

如何使用Python SDK运行已有的Amazon SageMaker Pipeline?

如何通过SageMaker Python SDK获取并运行已有管道

获取已有的Pipeline对象

你可以通过SageMaker Python SDK中的Pipeline类提供的from_pipeline_name方法,直接根据管道名称加载已创建的管道对象,这等价于AWS CLI的aws sagemaker describe-pipeline --pipeline-name foo操作。

示例代码如下:

import boto3
from sagemaker.session import Session
from sagemaker.workflow.pipeline import Pipeline

# 初始化SageMaker会话
sagemaker_session = Session(boto_session=boto3.Session())

# 根据管道名称加载已有管道
pipeline_name = "foo"
existing_pipeline = Pipeline.from_pipeline_name(
    pipeline_name=pipeline_name,
    sagemaker_session=sagemaker_session
)

# 查看管道详情
print(existing_pipeline.describe())

运行已加载的管道

获取到pipeline对象后,直接调用start方法即可触发管道运行,还可根据业务需求传入自定义参数:

# 启动管道运行,可选择性传入参数
execution = existing_pipeline.start(
    parameters={
        "InputDataUrl": "s3://your-bucket/input-data",
        "TrainingInstanceCount": 1
    }
)

# 查看运行状态
print(f"管道运行ID: {execution.execution_arn}")
print(f"当前运行状态: {execution.describe()['PipelineExecutionStatus']}")

补充说明

  • 确保你的Python环境已安装最新版SageMaker SDK:pip install --upgrade sagemaker
  • 执行代码的身份需具备SageMaker管道相关权限(如sagemaker:DescribePipeline、sagemaker:StartPipelineExecution等)

内容的提问来源于stack exchange,提问作者Marek Grzenkowicz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 06:18:24