建立和連接生命週期組態 - Amazon SageMaker AI

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

建立和連接生命週期組態

您可以使用 AWS 管理主控台 或 建立和連接生命週期組態 AWS Command Line Interface。

建立和連接生命週期組態 (AWS CLI)

重要

開始之前,請先完成以下先決條件:

下列程序展示如何建立生命週期組態指令碼,列印程式碼編輯器或 JupyterLab 內的 Hello World

注意

每個指令碼最多可以有 16,384 個字元。

  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 應用程式時 AWS 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] } }'

下列命令為程式碼編輯器應用程式建立一個具有生命週期組態的使用者設定檔。將來自上述步驟的生命週期組態 ARN 新增至使用者的 CodeEditorAppSettings。您可以傳遞生命週期組態清單,同時新增多個生命週期組態。當使用者透過 AWS CLI啟動程式碼編輯器應用程式時,他們可以指定生命週期組態,而非使用預設生命週期組態。使用者傳遞的生命週期組態必須屬於 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" } }'

下列命令為程式碼編輯器應用程式建立一個具有生命週期組態的使用者設定檔。將來自上述步驟的生命週期組態 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" } }'

建立和連接生命週期組態 (主控台)

若要在 中建立和連接生命週期組態 AWS 管理主控台,請導覽至 Amazon SageMaker AI 主控台,然後在左側導覽中選擇生命週期組態。主控台會引導您完成建立生命週期組態的程序。