本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立和連接生命週期組態
您可以使用 AWS 管理主控台 或 建立和連接生命週期組態 AWS Command Line Interface。
建立和連接生命週期組態 (AWS CLI)
重要
開始之前,請先完成以下先決條件:
-
AWS CLI 按照安裝目前 AWS CLI 版本中的步驟更新 。
-
從您的本機電腦執行
aws configure並提供您的 AWS 登入資料。如需 AWS 登入資料的相關資訊,請參閱了解並取得您的 AWS 登入資料。 -
加入 Amazon SageMaker AI 網域。如需相關概念資訊,請參閱 Amazon SageMaker AI 網域概觀。如需快速入門指南,請參閱使用 Amazon SageMaker AI 的快速設定。
下列程序展示如何建立生命週期組態指令碼,列印程式碼編輯器或 JupyterLab 內的 Hello World。
注意
每個指令碼最多可以有 16,384 個字元。
-
從您的本機電腦中,使用以下內容建立名為
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 \ --regionregion\ --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-iddomain-id\ --user-profile-nameuser-profile-name\ --regionregion\ --user-settings '{ "JupyterLabAppSettings": { "LifecycleConfigArns": [lifecycle-configuration-arn-list] } }'
下列命令為程式碼編輯器應用程式建立一個具有生命週期組態的使用者設定檔。將來自上述步驟的生命週期組態 ARN 新增至使用者的 CodeEditorAppSettings。您可以傳遞生命週期組態清單,同時新增多個生命週期組態。當使用者透過 AWS CLI啟動程式碼編輯器應用程式時,他們可以指定生命週期組態,而非使用預設生命週期組態。使用者傳遞的生命週期組態必須屬於 CodeEditorAppSettings 中的生命週期組態清單。
# Create a new UserProfile aws sagemaker create-user-profile --domain-iddomain-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-iddomain-id\ --user-profile-nameuser-profile-name\ --regionregion\ --user-settings '{ "JupyterLabAppSettings": { "BuiltInLifecycleConfigArn":"lifecycle-configuration-arn" } }'
下列命令為程式碼編輯器應用程式建立一個具有生命週期組態的使用者設定檔。將來自上述步驟的生命週期組態 ARN 新增至使用者設定檔的 CodeEditorAppSettings。使用者傳遞的生命週期組態必須屬於 CodeEditorAppSettings 中的生命週期組態清單。
# Update a UserProfile aws sagemaker update-user-profile --domain-iddomain-id\ --user-profile-nameuser-profile-name\ --regionregion\ --user-settings '{ "CodeEditorAppSettings": { "BuiltInLifecycleConfigArn":"lifecycle-configuration-arn" } }'
建立和連接生命週期組態 (主控台)
若要在 中建立和連接生命週期組態 AWS 管理主控台,請導覽至 Amazon SageMaker AI 主控台