如何在SageMaker Studio中删除Pipeline执行记录?
删除SageMaker Studio Pipeline单条执行记录的替代方案
目前AWS SageMaker确实没有提供直接删除单个Pipeline执行记录的API(无论是boto3还是CLI),但可以通过以下方法实现界面整洁的需求:
方法1:修改执行记录元数据实现隐藏效果
利用update_pipeline_execution()接口修改目标执行记录的名称或描述,添加归档标记,之后在Studio界面通过名称筛选即可排除这些记录:
import boto3 sagemaker_client = boto3.client('sagemaker') # 替换为你的Pipeline执行ARN execution_arn = "arn:aws:sagemaker:us-east-1:123456789012:pipeline-execution/my-pipeline/abc123" # 更新执行记录名称与描述,标记为归档状态 sagemaker_client.update_pipeline_execution( PipelineExecutionArn=execution_arn, PipelineExecutionDisplayName="FAILED_EXECUTION_ARCHIVED_20240520", PipelineExecutionDescription="已归档的失败执行记录" )
方法2:添加标签实现筛选过滤
给目标执行记录添加自定义标签,之后在SageMaker Studio的Pipeline页面通过标签筛选,只展示未归档的记录:
# 给执行记录添加归档标签 sagemaker_client.add_tags( ResourceArn=execution_arn, Tags=[ {'Key': 'Archive', 'Value': 'Yes'}, {'Key': 'Status', 'Value': 'Failed'} ] )
在Studio界面操作时,点击Pipeline页面的「筛选」按钮,选择标签Archive: No即可只显示活跃执行记录。
方法3:批量处理失败执行记录
如果有大量失败执行记录需要处理,可以写脚本批量获取所有失败执行,统一修改元数据或添加标签:
import boto3 sagemaker_client = boto3.client('sagemaker') pipeline_name = "my-pipeline" # 获取指定Pipeline下的所有失败执行记录 response = sagemaker_client.list_pipeline_executions( PipelineName=pipeline_name, PipelineExecutionStatusEquals='Failed' ) # 批量更新执行记录标记 for execution in response['PipelineExecutionSummaries']: exec_arn = execution['PipelineExecutionArn'] sagemaker_client.update_pipeline_execution( PipelineExecutionArn=exec_arn, PipelineExecutionDisplayName=f"ARCHIVED_{execution['PipelineExecutionDisplayName']}" )
需要注意的是,这些方法并没有真正删除执行记录,而是通过元数据管理实现界面上的隐藏——因为SageMaker目前不支持彻底删除单条执行记录的操作。
内容的提问来源于stack exchange,提问作者Giuseppe La Gualano
相关产品推荐
相关产品推荐

