[英]type of argument target must be aws_cdk.CfnResource; got aws_cdk.aws_iam.Role instead
I am trying to deploy sagemaker endpoints using CDK [python] from model artefacts in S3.我正在尝试使用来自 S3 中 model 人工制品的 CDK [python] 部署 sagemaker 端点。
The Sagemaker model requires execution_rol_arn. Sagemaker model 需要 execution_rol_arn。 So I created a role using CDK and passed it as a parameter for the sagemaker model. But It says Role does not exist when creating the model. But if add the dependency on resources by this command
sagemaker_model.add_depends_on(model_role)
.所以我使用 CDK 创建了一个角色并将其作为参数传递给 sagemaker model。但是它说创建 model 时角色不存在。但是如果通过此命令添加对资源的依赖
sagemaker_model.add_depends_on(model_role)
。 It gives me this error.它给了我这个错误。
type of argument target must be aws_cdk.CfnResource; got aws_cdk.aws_iam.Role instead
My cdk code for sagemaker model and Iam role我的 sagemaker model 和 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"
]
))
Things get a bit messy when you move between between the L1 ( CfnModel
) and L2 ( Role
) abstraction levels .当您在 L1 (
CfnModel
) 和 L2 ( Role
)抽象级别之间移动时,事情会变得有点混乱。 You need to use the so-called ecape hatch syntax :您需要使用所谓的转义舱口语法:
cfnRole = cast(iam.CfnRole, model_role.node.default_child) # cast if using typings
sagemaker_model.add_depends_on(cfnRole)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.