本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
创建和附加生命周期配置
您可以使用 AWS Management Console 或创建和附加生命周期配置 AWS Command Line Interface。
创建和附加生命周期配置 (AWS CLI)
重要
在开始之前,请满足以下先决条件:
-
AWS CLI 按照安装当前 AWS CLI 版本中的步骤进行更新。
-
在您的本地计算机上运行
aws configure
并提供您的 AWS 凭据。有关 AWS 证书的信息,请参阅了解和获取您的 AWS 证书。 -
登录 Amazon SageMaker AI 域名。有关概念性信息,请参阅 亚马逊 SageMaker AI 域名概述。有关快速入门指南,请参阅 使用 Amazon A SageMaker I 的快速设置。
以下过程说明如何创建Hello World
可在代码编辑器或中打印的生命周期配置脚本 JupyterLab。
注意
每个脚本最多可以包含 16384 个字符。
-
在本地计算机上,创建一个名为
my-script.sh
的文件,内容如下:#!/bin/bash set -eux echo 'Hello World!'
-
使用以下方法将
my-script.sh
文件转换为 base64 格式。此要求可防止因空格和换行编码而出现错误。LCC_CONTENT=`openssl base64 -A -in my-script.sh`
-
创建用于 Studio 的生命周期配置。下面的命令创建一个生命周期配置,该配置在启动关联的
JupyterLab
应用程序时运行:aws sagemaker create-studio-lifecycle-config \ --region
region
\ --studio-lifecycle-config-namemy-lcc
\ --studio-lifecycle-config-content $LCC_CONTENT \ --studio-lifecycle-config-app-typeapplication-type
对于
studio-lifecycle-config-app-type
,请指定CodeEditor
或JupyterLab
。注意
为新创建的生命周期配置返回的 ARN。将生命周期配置附加到应用程序时需要此 ARN。
为确保正确自定义环境,用户和管理员使用不同的命令来附加生命周期配置。
要附加生命周期配置,必须更新域的 UserSettings
或用户配置文件。在域级别关联的生命周期配置脚本由所有用户继承。但是,在用户配置文件级别关联的脚本的作用域限定为特定用户。
您可以使用以下命令创建附加生命周期配置的新用户配置文件、域或空间:
以下命令使用 JupyterLab 应用程序的生命周期配置创建用户配置文件。将上一步中的生命周期配置 ARN 添加到用户的 JupyterLabAppSettings
中。您可以通过传递列表同时添加多个生命周期配置。当用户使用启动 JupyterLab 应用程序时 AWS CLI,他们可以指定生命周期配置,而不是使用默认配置。用户传递的生命周期配置必须属于 JupyterLabAppSettings
中的生命周期配置列表。
# Create a new UserProfile aws sagemaker create-user-profile --domain-id
domain-id
\ --user-profile-nameuser-profile-name
\ --regionregion
\ --user-settings '{ "JupyterLabAppSettings": { "LifecycleConfigArns": [lifecycle-configuration-arn-list
] } }'
下面的命令为 Code Editor 应用程序创建了具有生命周期配置的用户配置文件。将上一步中的生命周期配置 ARN 添加到用户的 CodeEditorAppSettings
中。您可以通过传递列表同时添加多个生命周期配置。当用户使用 AWS CLI启动 Code Editor 应用程序时,他们可以指定生命周期配置,而不是使用默认配置。用户传递的生命周期配置必须属于 CodeEditorAppSettings
中的生命周期配置列表。
# Create a new UserProfile aws sagemaker create-user-profile --domain-id
domain-id
\ --user-profile-nameuser-profile-name
\ --regionregion
\ --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-nameuser-profile-name
\ --regionregion
\ --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-nameuser-profile-name
\ --regionregion
\ --user-settings '{ "CodeEditorAppSettings": { "BuiltInLifecycleConfigArn":"lifecycle-configuration-arn
" } }'
创建和附加生命周期配置(管理控制台)
要在中创建和附加生命周期配置 AWS Management Console,请导航至 Amazon A SageMaker I 控制台