【问题标题】:Error when deploying cross account Sagemaker Endpoints部署跨账户 Sagemaker 端点时出错
【发布时间】:2022-08-02 21:34:03
【问题描述】:

我正在使用 cdk 在跨账户上下文中部署 Sagemaker 端点。

创建 Sagemaker Endpoint 时出现以下错误: 无法从 URL:\"s3://.../model.tar.gz\" 下载容器 \"container_1\" 的模型数据。请确保 URL 中有一个对象,并且传递给 CreateModel 的角色有权下载该对象。

这里有一些有用的细节。

我有两个帐户:

  • 账户A:包括已保存模型工件的加密s3存储桶、最新批准版本的Sagemaker模型包组以及在账户A和账户B中部署端点的CodePipeline。
  • 账户 B:包括 CodePipeline 在账户 A 中部署的端点。

在 AccountS 中:

  • 为存储桶和用于加密该存储桶的 kms 密钥设置了跨账户权限
// Create bucket and kms key to be used by Sagemaker Pipeline

        //KMS
        const sagemakerKmsKey = new Key(
            this,
            \"SagemakerBucketKMSKey\",
            {
                description: \"key used for encryption of data in Amazon S3\",
                enableKeyRotation: true,
                policy: new PolicyDocument(
                    {
                        statements:[
                            new PolicyStatement(
                                {
                                    actions:[\"kms:*\"],
                                    effect: Effect.ALLOW,
                                    resources:[\"*\"],
                                    principals: [new AccountRootPrincipal()]
                                }
                            ),
                            new PolicyStatement(
                                {
                                    actions:[
                                        \"kms:*\"
                                    ],
                                    effect: Effect.ALLOW,
                                    resources:[\"*\"],
                                    principals: [
                                        new ArnPrincipal(`arn:${Aws.PARTITION}:iam::${AccountA}:root`),
                                        new ArnPrincipal(`arn:${Aws.PARTITION}:iam::${AccountB}:root`),
                                    ]
                                }
                            )
                        ]
                    }
                )
            }
        )

        // S3 Bucket
        const sagemakerArtifactBucket = new Bucket(
            this,
            \"SagemakerArtifactBucket\",
            {
                bucketName:`mlops-${projectName}-${Aws.REGION}`,
                encryptionKey:sagemakerKmsKey,
                versioned:false,
                removalPolicy: RemovalPolicy.DESTROY
            }
        )
        
        sagemakerArtifactBucket.addToResourcePolicy(
            new PolicyStatement(
                {
                    actions: [
                        \"s3:*\",
                    ],
                    resources: [
                        sagemakerArtifactBucket.bucketArn,
                        `${sagemakerArtifactBucket.bucketArn}/*`
                    ],
                    principals: [
                        new ArnPrincipal(`arn:${Aws.PARTITION}:iam::${AccountA}:root`),
                        new ArnPrincipal(`arn:${Aws.PARTITION}:iam::${AccountB}:root`),
                    ]
                }
            )
        )
  • CodeDeploy 操作用于在 AccountS 和 Account 中部署 Sagemaker 端点。
// Define Code Build Deploy Staging Action
        const deployStagingAction = new CloudFormationCreateUpdateStackAction(
            {
                actionName: \"DeployStagingAction\",
                runOrder: 1,
                adminPermissions: false,
                stackName: `${projectName}EndpointStaging`,
                templatePath: cdKSynthArtifact.atPath(\"staging.template.json\"),
                replaceOnFailure: true,
                role: Role.fromRoleArn(
                    this,
                    \"StagingActionRole\",
                    `arn:${Aws.PARTITION}:iam::${AccountB}:role/cdk-hnb659fds-deploy-role-${AccountB}-${Aws.REGION}`,
                ),
                deploymentRole: Role.fromRoleArn(
                    this,
                    \"StagingDeploymentRole\",
                    `arn:${Aws.PARTITION}:iam::${AccountB}:role/cdk-hnb659fds-cfn-exec-role-${AccountB}-${Aws.REGION}`
                ),
                cfnCapabilities: [
                    CfnCapabilities.AUTO_EXPAND,
                    CfnCapabilities.NAMED_IAM
                ]
            }
        )

具体来说,创建 Sagemaker 模型和 Sagemaker 端点的角色应该是 cdk-hnb659fds-cfn-exec-role,如 CloudTrail 所示,但出于测试目的,我已授予他们两个管理员权限(错误仍然出现) .

AccountS 中的部署正确执行,这意味着存储桶位置正确。

注意:一切都正确部署到 Sagemaker 端点。

  • 我有点困惑为什么您使用这些主体.../root,不应该被您在下面在 deployStagingAction 中使用的角色代替吗?
  • \"root\" 表示您正在授予在指定帐户中创建的所有角色的权限。
  • 您是否在此处关注过这篇文章:aws.amazon.com/premiumsupport/knowledge-center/…

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


【解决方案1】:

我设法找到了问题。

问题在于,即使存储桶是使用自定义 KMSKey 创建的,存储在存储桶中的工件也是由 Estimator 生成的。如果您不指定output_kms_key参数,它将使用托管 kms 密钥,该密钥与用于 s3 存储桶的密钥不同。

即使该问题与跨帐户权限无关,我也会将其留在这里,以防有人遇到类似问题。

【讨论】:

    猜你喜欢
    • 2020-01-25
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    相关资源
    最近更新 更多