创建和附加生命周期配置 - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建和附加生命周期配置

您可以使用 Amazon Web Services Management Console 或创建和附加生命周期配置 Amazon Command Line Interface。

创建和附加生命周期配置 (Amazon CLI)

重要

在开始之前,请满足以下先决条件:

以下过程说明如何创建Hello World可在代码编辑器或中打印的生命周期配置脚本 JupyterLab。

注意

每个脚本最多可以包含 16384 个字符

  1. 在本地计算机上,创建一个名为 my-script.sh 的文件,内容如下:

    #!/bin/bash set -eux echo 'Hello World!'
  2. 使用以下方法将 my-script.sh 文件转换为 base64 格式。此要求可防止因空格和换行编码而出现错误。

    LCC_CONTENT=`openssl base64 -A -in my-script.sh`
  3. 创建用于 Studio 的生命周期配置。下面的命令创建一个生命周期配置,该配置在启动关联的 JupyterLab 应用程序时运行:

    aws sagemaker create-studio-lifecycle-config \ --region region \ --studio-lifecycle-config-name my-lcc \ --studio-lifecycle-config-content $LCC_CONTENT \ --studio-lifecycle-config-app-type application-type

    对于 studio-lifecycle-config-app-type,请指定 CodeEditorJupyterLab

    注意

    为新创建的生命周期配置返回的 ARN。将生命周期配置附加到应用程序时需要此 ARN。

为确保正确自定义环境,用户和管理员使用不同的命令来附加生命周期配置。

要附加生命周期配置,必须更新域的 UserSettings 或用户配置文件。在域级别关联的生命周期配置脚本由所有用户继承。但是,在用户配置文件级别关联的脚本的作用域限定为特定用户。

您可以使用以下命令创建附加生命周期配置的新用户配置文件、域或空间:

以下命令使用 JupyterLab 应用程序的生命周期配置创建用户配置文件。将上一步中的生命周期配置 ARN 添加到用户的 JupyterLabAppSettings 中。您可以通过传递列表同时添加多个生命周期配置。当用户使用启动 JupyterLab 应用程序时 Amazon CLI,他们可以指定生命周期配置,而不是使用默认配置。用户传递的生命周期配置必须属于 JupyterLabAppSettings 中的生命周期配置列表。

# Create a new UserProfile aws sagemaker create-user-profile --domain-id domain-id \ --user-profile-name user-profile-name \ --region region \ --user-settings '{ "JupyterLabAppSettings": { "LifecycleConfigArns": [lifecycle-configuration-arn-list] } }'

下面的命令为 Code Editor 应用程序创建了具有生命周期配置的用户配置文件。将上一步中的生命周期配置 ARN 添加到用户的 CodeEditorAppSettings 中。您可以通过传递列表同时添加多个生命周期配置。当用户使用 Amazon CLI启动 Code Editor 应用程序时,他们可以指定生命周期配置,而不是使用默认配置。用户传递的生命周期配置必须属于 CodeEditorAppSettings 中的生命周期配置列表。

# Create a new UserProfile aws sagemaker create-user-profile --domain-id domain-id \ --user-profile-name user-profile-name \ --region region \ --user-settings '{ "CodeEditorAppSettings": { "LifecycleConfigArns": [lifecycle-configuration-arn-list] } }'

要附加生命周期配置,必须更新用户配置文件的 UserSettings

以下命令使用 JupyterLab 应用程序的生命周期配置创建用户配置文件。将上一步中的生命周期配置 ARN 添加到用户配置文件的 JupyterLabAppSettings 中。

# Update a UserProfile aws sagemaker update-user-profile --domain-id domain-id \ --user-profile-name user-profile-name \ --region region \ --user-settings '{ "JupyterLabAppSettings": { "BuiltInLifecycleConfigArn":"lifecycle-configuration-arn" } }'

下面的命令为 Code Editor 应用程序创建了具有生命周期配置的用户配置文件。将上一步中的生命周期配置 ARN 添加到用户配置文件的 CodeEditorAppSettings 中。用户传递的生命周期配置必须属于 CodeEditorAppSettings 中的生命周期配置列表。

# Update a UserProfile aws sagemaker update-user-profile --domain-id domain-id \ --user-profile-name user-profile-name \ --region region \ --user-settings '{ "CodeEditorAppSettings": { "BuiltInLifecycleConfigArn":"lifecycle-configuration-arn" } }'

创建和附加生命周期配置(管理控制台)

要在中创建和附加生命周期配置 Amazon Web Services Management Console,请导航至 Amazon A SageMaker I 控制台,然后在左侧导航栏中选择生命周期配置。管理控制台将引导您完成生命周期配置的创建过程。