AddingConditionStepinSagemakerPipeline,failswithAccessdeinedpermission
创始人
2024-07-26 17:00:59
0

该问题可能是由于缺少对AWS StepFunctions服务的访问权限导致的。需要通过IAM角色为Sagemaker Notebook、pipeline中的Sagemaker Step和Sagemaker Model构建器分别授予StepFunctionsFullAccess和SageMakerFullAccess权限。可以通过以下方式在IAM角色策略中实现:

import boto3
from pprint import pprint

iam = boto3.client('iam')
role_name = 'my_role_name'

# add stepFunctions full access to IAM role policy
stepFunctions_policy = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "states:*",
      "Resource": "*"
    }
  ]
}

iam.update_assume_role_policy(PolicyDocument=stepFunctions_policy, RoleName=role_name)


# add Sagemaker full access to IAM role policy
sagemaker_policy = {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:*"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": "*"
        }
    ]
}

iam.put_role_policy(PolicyDocument=sagemaker_policy, RoleName=role_name)

完成IAM授权后,将ConditionStep添加到Sagemaker Pipeline的代码可以类似于以下方式:

from sagemaker.workflow.conditions import ConditionLessThanOrEqualTo
from sagemaker.workflow.steps import ProcessingStep, TrainingStep, CacheConfig, CreateModelStep
from sagemaker.workflow.pipeline import Pipeline
from sagemaker.workflow.step_collections import RegisterModel



condition_step = ConditionLessThanOrEqualTo(left=best_model_acc, right=target_acc)

create_model_step = CreateModelStep(
    name="MyCreateModelStep",
    model_name=get_model_name_from_somewhere(),
    instance_type="ml.t2.medium",
    image_uri=train_image_uri,
    model_data=train_data_uri,
    role=sagemaker_role,
    model_output=model_data,
    metadata=model_artifact_metadata,
    **{'Condition': condition_step}
)

# construct pipeline with condition_step and create_model_step

相关内容

热门资讯

Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Aksnginxdomainb... 在AKS集群中,可以使用Nginx代理服务器实现根据域名进行路由。以下是具体步骤:部署Nginx i...
Alertmanager中的基... Alertmanager中可以使用repeat_interval选项指定在一个告警重复发送前必须等待...
AddSingleton在.N... 在C#中创建Singleton对象通常是通过私有构造函数和静态属性来实现,例如:public cla...