本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立和連接生命週期組態
您可以使用 AWS Management Console 或 建立和連接生命週期組態 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 \ --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 應用程式生命週期組態的使用者設定檔。將上一個步驟JupyterLabAppSettings
的生命週期組態 ARN 新增至使用者的 。您可以傳遞多個生命週期組態的清單,同時新增多個生命週期組態。當使用者使用 啟動 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 應用程式生命週期組態的使用者設定檔。將上一個步驟CodeEditorAppSettings
的生命週期組態 ARN 新增至使用者的 。您可以傳遞多個生命週期組態的清單,同時新增多個生命週期組態。當使用者使用 啟動 Code Editor 應用程式時 AWS CLI,他們可以指定生命週期組態,而不是使用預設組態。使用者傳遞的生命週期組態必須屬於 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 SageMaker AI 主控台