跳至内容

当我在 SageMaker 人工智能 Notebook 实例或 SageMaker Studio 域上启动预签名 URL 时,为什么会收到错误?

2 分钟阅读
0

我想在 Amazon SageMaker 人工智能 Notebook 实例或 Amazon SageMaker Studio 域上启动预签名 URL,但我收到了错误。

解决方案

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

当您在 SageMaker 人工智能 Notebook 实例或 SageMaker Studio 域上启动预签名 URL 时,可能会收到以下错误消息:

  • “身份验证令牌无效或已过期。申请新的预签名 URL 以继续使用 SageMaker。”
  • “用户 arn:aws:sts::account id:assumed-role/IAM role/IAM user 无权对资源 arn:aws:sagemaker:Region:account id:notebook-instance/notebook instance 执行 sagemaker:CreatePresignedNotebookInstanceUrl,因为没有基于身份的策略允许 sagemaker:CreatePresignedNotebookInstanceUrl 操作”
  • “用户 arn:aws:sts::account id:assumed-role/IAM role/SageMaker 无权对资源 arn:aws:sagemaker:Region:account id:user-profile/domain id/user profile name 执行 sagemaker:CreatePresignedDomainUrl,因为没有基于身份的策略允许 sagemaker:CreatePresignedDomainUrl 操作”

要对这些问题进行故障排除,请完成您已收到的错误消息的解决方法。

“Invalid or Expired Auth Token”(授权令牌无效或已过期)错误

CreatePresignedNotebookInstanceUrlCreatePresignedDomainUrl 中的 SessionExpirationDurationInSeconds 参数超出 12 小时的最大持续时间时,您会收到 Invalid or Expired Auth Token(授权令牌无效或已过期)错误。要解决此问题,请清除 Web 浏览器中的 Cookie 和会话数据。然后,使用 SageMaker AI 控制台、AWS CLI 或 Python SDK 生成新的预签名 URL。

SageMaker 人工智能 Notebook 实例

要使用控制台,请完成以下步骤:

  1. 打开 SageMaker 人工智能控制台
  2. 在导航窗格的 Applications and IDEs(应用程序和 IDE)下,选择 Notebooks(Notebook)。
  3. 选择您的 Notebook 实例。
  4. 选择 Open Jupyter(打开 Jupyter)或 Open JupyterLab(打开 JupyterLab)。

要使用 AWS CLI,请运行 create-presigned-notebook-instance-url 命令:

aws sagemaker create-presigned-notebook-instance-url --notebook-instance-name example-notebook-instance-name --session-expiration-duration-in-seconds example-session-expiration-duration

**注意:**将 example-notebook-instance-nameexample-session-expiration-duration 替换为您的值。

要使用 Python SDK Boto3,请运行 create-presigned-notebook-instance-url 命令:

import boto3

client = boto3.client('sagemaker')

response = client.create_presigned_notebook_instance_url(
    NotebookInstanceName=example-notebook-name,
    SessionExpirationDurationInSeconds=example-session-expiration-duration
)

**注意:**将 example-notebook-nameexample-session-expiration-duration 替换为您的值。

AWS CLI 或 Python SDK 生成的预签名 URL 仅在 5 分钟内有效。5 分钟后,您必须生成一个新的预签名 URL。

SageMaker Studio 域

要使用控制台,请完成以下步骤:

  1. 打开 SageMaker 人工智能控制台
  2. 在导航窗格中的 Admin configurations(管理员配置)下,选择 Domains(域)。
  3. 选择您的域。
  4. 选择 User profiles(用户配置文件),然后选择您的用户配置文件名称。
  5. 选择 Launch(启动),然后选择 Studio

要使用 AWS CLI,请运行 create-presigned-domain-url 命令:

aws sagemaker create-presigned-domain-url --domain-id example-domain-id --user-profile-name example-user-profile-name --session-expiration-duration-in-seconds example-session-expiration-duration

**注意:**将 example-domain-idexample-user-profile-nameexample-session-expiration-duration 替换为您的值。

要使用 Python SDK Boto3,请运行 create-presigned-domain-url 命令:

import boto3

client = boto3.client('sagemaker')

response = client.create_presigned_domain_url(
    DomainId=example-domain-id,
    UserProfileName=example-user-profile-name,
    SessionExpirationDurationInSeconds=example-session-expiration-duration,
)

**注意:**将 example-domain-idexample-user-profile-nameexample-session-expiration-duration 替换为您的值。

AWS CLI 或 Python SDK 生成的预签名 URL 仅在 5 分钟内有效。5 分钟后,您必须生成一个新的预签名 URL。

“Not authorized to perform”(无权执行)错误

要启动 SageMaker 人工智能 Notebook 或 SageMaker Studio 域,您的 AWS Identity and Access Management (IAM) 角色必须具有创建预签名 URL 的权限。

对于 SageMaker 人工智能 Notebook 实例,将 sagemaker:CreatePresignedNotebookInstanceUrl 操作添加到您的 IAM 角色的基于身份的策略中。对于 SageMaker Studio 域,将 sagemaker:CreatePresignedDomainUrl 操作添加到 IAM 策略中。

相关信息

通过 Amazon Virtual Private Cloud (Amazon VPC) 接口端点连接到 Notebook 实例

AWS 官方已更新 10 个月前