【问题标题】:type of argument target must be aws_cdk.CfnResource; got aws_cdk.aws_iam.Role instead参数目标的类型必须是 aws_cdk.CfnResource;取而代之的是 aws_cdk.aws_iam.Role
【发布时间】:2022-11-27 12:22:15
【问题描述】:

我正在尝试使用来自 S3 模型工件的 CDK [python] 部署 sagemaker 端点。

Sagemaker 模型需要 execution_rol_arn。所以我使用 CDK 创建了一个角色并将其作为参数传递给 sagemaker 模型。但是它说创建模型时角色不存在。 但是如果通过这个命令添加对资源的依赖sagemaker_model.add_depends_on(model_role) .它给了我这个错误。

type of argument target must be aws_cdk.CfnResource; got aws_cdk.aws_iam.Role instead

我的 sagemaker 模型和 Iam 角色的 cdk 代码

        sagemaker_model = aws_sagemaker.CfnModel(
            self,
            model_name,
            execution_role_arn=model_role.role_arn,
            model_name=model_name,
            primary_container=sagemaker_primary_container_definition,
        )
        model_role = Role(
            self,
            f"{construct_id}_role",
            assumed_by=ServicePrincipal("sagemaker.amazonaws.com"),
        )
        model_role.add_to_policy(PolicyStatement(
            resources=["*"],
            actions= [
                "cloudwatch:PutMetricData",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:CreateLogGroup",
                "logs:DescribeLogStreams",
                "s3:GetObject",
                "s3:ListBucket",
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage"
            ]
        ))

【问题讨论】:

    标签: amazon-web-services aws-cdk amazon-sagemaker


    【解决方案1】:

    当您在 L1 (CfnModel) 和 L2 (Role) abstraction levels 之间移动时,事情会变得有点混乱。你需要使用所谓的ecape hatch syntax:

    cfnRole = cast(iam.CfnRole, model_role.node.default_child) # cast if using typings
    
    sagemaker_model.add_depends_on(cfnRole)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多