该问题可能是由于缺少对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
                
            
                    上一篇:AddingClassPropertiesbasedonGeneric(基于泛型添加类属性)
                
下一篇:AddingconditiontoexistingTerraformcodethatwassuccessfullyrun