

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

# 使用程式碼編輯器
<a name="code-editor-use"></a>

本節中的主題提供使用程式碼編輯器的指南，包括如何啟動、新增連線 AWS 服務、關閉資源等。建立程式碼編輯器空間後，您可以透過瀏覽器直接存取程式碼編輯器工作階段。

在程式碼編輯器環境內，您可以執行下列動作：
+ 存取您主目錄中保存的所有成品
+ 複製您的 GitHub 儲存庫並遞交變更
+ 存取 SageMaker Python SDK

您可以返回 Studio 來檢閱程式碼編輯器環境中建立的任何資產，例如實驗、管道或訓練任務。

**Topics**
+ [檢查程式碼編輯器的版本](code-editor-use-version.md)
+ [程式碼編輯器應用程式執行個體和映像](code-editor-use-instances.md)
+ [在 Studio 中啟動程式碼編輯器應用程式](code-editor-use-studio.md)
+ [使用 啟動程式碼編輯器應用程式 AWS CLI](code-editor-launch-cli.md)
+ [在程式碼編輯器中複製儲存庫](code-editor-use-clone-a-repository.md)
+ [程式碼編輯器連線和延伸模組](code-editor-use-connections-and-extensions.md)
+ [關閉程式碼編輯器資源](code-editor-use-log-out.md)

# 檢查程式碼編輯器的版本
<a name="code-editor-use-version"></a>

下列步驟說明如何檢查程式碼編輯器應用程式的版本。

**檢查程式碼編輯器應用程式版本**

1. 啟動並執行程式碼編輯器空間，然後導覽至程式碼編輯器應用程式 UI。如需詳細資訊，請參閱[在 Studio 中啟動程式碼編輯器應用程式](code-editor-use-studio.md)。

1. 在程式碼編輯器 UI 的左上角，選擇功能表按鈕 (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-menu-icon.png))。然後，選擇**說明**。然後，選擇**關於**。

# 程式碼編輯器應用程式執行個體和映像
<a name="code-editor-use-instances"></a>

只有某些執行個體與程式碼編輯器應用程式相容。您可以從**執行個體**下拉式功能表中選擇與您使用案例相容的執行個體類型。

**快速啟動**執行個體的啟動速度比其他執行個體快得多。如需在 Studio 中快速啟動執行個體類型的詳細資訊，請參閱[可與 Amazon SageMaker Studio Classic 筆記本搭配使用的執行個體類型](notebooks-available-instance-types.md)。

**注意**  
如果您在設定程式碼編輯器應用程式時使用 GPU 執行個體類型，您也必須使用 GPU 型映像。當您選取執行個體類型時，程式碼編輯器空間 UI 會自動選取相容的映像。

在空間內，您的資料會儲存在與執行個體生命週期無關的 Amazon EBS 磁碟區中。當您變更執行個體時，不會遺失資料。如果您的程式碼編輯器空間是 `Running`，您必須在變更執行個體類型之前停止空間。

下表列出每個區域的可用程式碼編輯器 CPU 和 GPU 映像的 ARN。


|  區域  |  CPU  |  GPU  | 
| --- | --- | --- | 
|  us-east-1  | arn:aws:sagemaker:us-east-1:885854791233:image/sagemaker-distribution-cpu |  arn:aws:sagemaker:us-east-1:885854791233:image/sagemaker-distribution-gpu | 
|  us-east-2  | arn:aws:sagemaker:us-east-2:37914896644:image/sagemaker-distribution-cpu | arn:aws:sagemaker:us-east-2:37914896644:image/sagemaker-distribution-gpu | 
|  us-west-1  | arn:aws:sagemaker:us-west-1:053634841547:image/sagemaker-distribution-cpu | arn:aws:sagemaker:us-west-1:053634841547:image/sagemaker-distribution-gpu | 
|  us-west-2  | arn:aws:sagemaker:us-west-2:542918446943:image/sagemaker-distribution-cpu |  arn:aws:sagemaker:us-west-2:542918446943:image/sagemaker-distribution-gpu | 
|  af-south-1  | arn:aws:sagemaker:af-south-1:238384257742:image/sagemaker-distribution-cpu | arn:aws:sagemaker:af-south-1:238384257742:image/sagemaker-distribution-gpu | 
|  ap-east-1  | arn:aws:sagemaker:ap-east-1:523751269255:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-east-1:523751269255:image/sagemaker-distribution-gpu | 
|  ap-south-1  | arn:aws:sagemaker:ap-south-1:245090515133:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-south-1:245090515133:image/sagemaker-distribution-gpu | 
|  ap-northeast-2  | arn:aws:sagemaker:ap-northeast-2:064688005998:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-northeast-2:064688005998:image/sagemaker-distribution-gpu | 
|  ap-southeast-1  | arn:aws:sagemaker:ap-southeast-1:022667117163:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-southeast-1:022667117163:image/sagemaker-distribution-gpu | 
|  ap-southeast-2  | arn:aws:sagemaker:ap-southeast-2:648430277019:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-southeast-2:648430277019:image/sagemaker-distribution-gpu | 
|  ap-northeast-1  | arn:aws:sagemaker:ap-northeast-1:010972774902:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-northeast-1:010972774902:image/sagemaker-distribution-gpu | 
|  ca-central-1  | arn:aws:sagemaker:ca-central-1:481561238223:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ca-central-1:481561238223:image/sagemaker-distribution-gpu | 
|  eu-central-1  | arn:aws:sagemaker:eu-central-1:545423591354:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-central-1:545423591354:image/sagemaker-distribution-gpu | 
|  eu-west-1  | arn:aws:sagemaker:eu-west-1:819792524951:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-west-1:819792524951:image/sagemaker-distribution-gpu | 
|  eu-west-2  | arn:aws:sagemaker:eu-west-2:021081402939:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-west-2:021081402939:image/sagemaker-distribution-gpu | 
|  eu-west-3  | arn:aws:sagemaker:eu-west-3:856416204555:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-west-3:856416204555:image/sagemaker-distribution-gpu | 
|  eu-north-1  | arn:aws:sagemaker:eu-north-1:175620155138:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-north-1:175620155138:image/sagemaker-distribution-gpu | 
|  eu-south-1  | arn:aws:sagemaker:eu-south-1:810671768855:image/sagemaker-distribution-cpu | arn:aws:sagemaker:eu-south-1:810671768855:image/sagemaker-distribution-gpu | 
|  sa-east-1  | arn:aws:sagemaker:sa-east-1:567556641782:image/sagemaker-distribution-cpu | arn:aws:sagemaker:sa-east-1:567556641782:image/sagemaker-distribution-gpu | 
|  ap-northeast-3  | arn:aws:sagemaker:ap-northeast-3:564864627153:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-northeast-3:564864627153:image/sagemaker-distribution-gpu | 
|  ap-southeast-3  | arn:aws:sagemaker:ap-southeast-3:370607712162:image/sagemaker-distribution-cpu | arn:aws:sagemaker:ap-southeast-3:370607712162:image/sagemaker-distribution-gpu | 
|  me-south-1  | arn:aws:sagemaker:me-south-1:523774347010:image/sagemaker-distribution-cpu | arn:aws:sagemaker:me-south-1:523774347010:image/sagemaker-distribution-gpu | 
|  me-central-1  | arn:aws:sagemaker:me-central-1:358593528301:image/sagemaker-distribution-cpu | arn:aws:sagemaker:me-central-1:358593528301:image/sagemaker-distribution-gpu | 
|  il-central-1  | arn:aws:sagemaker:il-central-1:080319125002:image/sagemaker-distribution-cpu | arn:aws:sagemaker:il-central-1:080319125002:image/sagemaker-distribution-gpu | 
|  cn-north-1  | arn:aws:sagemaker:cn-north-1:674439102856:image/sagemaker-distribution-cpu |  arn:aws:sagemaker:cn-north-1:674439102856:image/sagemaker-distribution-gpu  | 
|  cn-northwest-1  | arn:aws:sagemaker:cn-northwest-1:651871951035:image/sagemaker-distribution-cpu |  arn:aws:sagemaker:cn-northwest-1:651871951035:image/sagemaker-distribution-gpu  | 
|  us-gov-west-1  | arn:aws:sagemaker:us-gov-west-1:300992924816:image/sagemaker-distribution-cpu | arn:aws:sagemaker:us-gov-west-1:300992924816:image/sagemaker-distribution-gpu | 
|  us-gov-east-1  | arn:aws:sagemaker:us-gov-east-1:300993876623:image/sagemaker-distribution-cpu | arn:aws:sagemaker:us-gov-east-1:300993876623:image/sagemaker-distribution-gpu | 

如果您遇到執行個體限制，請聯絡您的管理員。若要為使用者取得更多儲存空間和運算，管理員可以請求提高使用者的 AWS 配額。如需要求配額增加的詳細資訊，請參閱 [Amazon SageMaker AI 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html)。

# 在 Studio 中啟動程式碼編輯器應用程式
<a name="code-editor-use-studio"></a>

若要透過 Studio 設定和存取您的程式碼編輯器整合式開發環境，您必須建立程式碼編輯器空間。如需 Studio 中空間的詳細資訊，請參閱 [Amazon SageMaker Studio 空間](studio-updated-spaces.md)。

![\[Studio UI 中的程式碼編輯器應用程式按鈕和概觀圖磚。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-studio-home.png)


下列程序說明如何建立和執行程式碼編輯器空間。

**建立和執行程式碼編輯器空間**

1. 啟動更新的 Studio 體驗。如需詳細資訊，請參閱[啟動 Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-launch.html)。

1. 執行以下任意一項：
   + 在更新的 Amazon SageMaker Studio UI 內，從**應用程式**功能表中選取**程式碼編輯器**。
   + 在更新的 Amazon SageMaker Studio UI 內，選擇 Studio 首頁的**概觀**區段中的**檢視程式碼編輯器空間**。

1. 在程式碼編輯器登陸頁面的右上角，選擇**建立程式碼編輯器空間**。

1. 輸入程式碼編輯器空間的名稱。名稱長度必須為 1-62 個字元，只能使用字母、數字和破折號。

1. 選擇**建立空間**。

1. 建立空間後，在選擇執行空間之前，您有一些選項：
   + 您可以編輯**儲存 (GB)**、**生命週期組態**或**連接自訂 EFS 檔案系統**設定。這些設定的選項會根據管理員規格提供。
   + 從**執行個體**下拉式功能表中，您可以選擇與您使用案例最相容的執行個體類型。從**映像**下拉式功能表中，您可以選擇 SageMaker Distribution 映像或管理員提供的自訂映像。
**注意**  
在 sagemaker-distribution 映像之間切換會變更正在使用的程式碼編輯器基礎版本，這可能會由於瀏覽器快取而導致不相容。在映像之間切換時，您應該清除瀏覽器快取。

     如果您在設定程式碼編輯器應用程式時使用 GPU 執行個體類型，您也必須使用 GPU 型映像。在空間內，您的資料會儲存在與執行個體生命週期無關的 Amazon EBS 磁碟區中。當您變更執行個體時，不會遺失資料。
**重要**  
允許 Studio 使用者建立空間的自訂 IAM 政策，也必須授與列出映像 (`sagemaker: ListImage`) 以檢視自訂映像的許可。若要新增許可，請參閱《*AWS Identity and Access Management* 使用者指南》中的[新增或移除身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。  
提供許可來建立 SageMaker AI 資源的 [AWS Amazon SageMaker AI 的 受管政策](security-iam-awsmanpol.md) 已包含建立這些資源時列出映像的許可。
**注意**  
若要更新空間設定，您必須先停止您的空間。如果您的程式碼編輯器使用執行個體搭配 NVMe 執行個體儲存體，則會在空間停止時刪除存放在 NVMe 存放區的任何資料。

1. 更新您的設定後，請在空間詳細資訊頁面中選擇**執行空間**。

1. 在空間的狀態為 `Running` 之後，選擇**開啟程式碼編輯器**以前往程式碼編輯器工作階段。

![\[Studio UI 中程式碼編輯器應用程式的空間詳細資訊頁面。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-open.png)


# 使用 啟動程式碼編輯器應用程式 AWS CLI
<a name="code-editor-launch-cli"></a>

若要透過 AWS Command Line Interface (AWS CLI) 設定和存取您的程式碼編輯器整合式開發環境，您必須建立程式碼編輯器空間。在進行下列步驟之前，請務必符合[完成事前準備](code-editor-admin-prerequisites.md)。使用下列程序來建立和執行程式碼編輯器空間。

**建立和執行程式碼編輯器空間**

1. 使用 AWS Identity and Access Management (IAM) 或 AWS IAM Identity Center 身分驗證存取空間。如需使用 存取空間的詳細資訊 AWS CLI，請參閱 中的*使用 存取空間 AWS Command Line Interface*[Amazon SageMaker Studio 空間](studio-updated-spaces.md)。

1. 使用下列命令建立應用程式，並將 `CodeEditor` 指定為 `app-type`。

   如果您在建立程式碼編輯器應用程式時使用 GPU 執行個體類型，您也必須使用 GPU 型映像。

   ```
   aws sagemaker create-app \
   --domain-id domain-id \
   --space-name space-name \
   --app-type CodeEditor \
   --app-name default \
   --resource-spec "SageMakerImageArn=arn:aws:sagemaker:region:account-id:image/sagemaker-distribution-cpu"
   ```

   如需可用程式碼編輯器映像 ARN 的詳細資訊，請參閱 [程式碼編輯器應用程式執行個體和映像](code-editor-use-instances.md)。

1. 程式碼編輯器應用程式處於服務狀態後，請使用預先簽章的 URL 啟動應用程式。您可以使用 `describe-app` API 來檢查您的應用程式是否處於服務中。使用 `create-presigned-domain-url` API 建立預先簽章的 URL：

   ```
   aws sagemaker create-presigned-domain-url \
   --domain-id domain-id \
   --space-name space-name \
   --user-profile-name user-profile-name \
   --session-expiration-duration-in-seconds 43200 \
   --landing-uri app:CodeEditor:
   ```

1. 開啟產生的 URL 以開始在您的程式碼編輯器應用程式中運作。

# 在程式碼編輯器中複製儲存庫
<a name="code-editor-use-clone-a-repository"></a>

您可以在程式碼編輯器應用程式 UI 的 **Explorer** 視窗中瀏覽資料夾並複製儲存庫。

若要複製儲存庫，請執行下列步驟：

**複製儲存庫**

1. 在瀏覽器中開啟您的程式碼編輯器應用程式，然後選擇左側導覽窗格中的**探索**按鈕 (![\[Icon representing multiple documents or pages stacked on top of each other.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-exploration-icon.png))。

1. 在 **Explorer** 視窗中選擇**複製儲存庫**。然後，提供儲存庫 URL 或在提示中挑選儲存庫來源。

1. 選擇一個資料夾，以將您的儲存庫複製至其中。請注意，預設程式碼編輯器資料夾為 `/home/sagemaker-user/`。複製您的儲存庫可能需要一些時間。

1. 若要開啟複製的儲存庫，請選擇**在新視窗中開啟**或**開啟**。

1.  若要返回程式碼編輯器應用程式 UI 首頁，請選擇**取消**。

1. 在儲存庫中，提示會詢問您是否信任新儲存庫中檔案的作者。您有兩個選擇：

   1. 若要信任資料夾並啟用所有功能，請選擇**是，我信任作者**。

   1. 若要以*受限模式*瀏覽儲存庫內容，請選擇**否，我不信任作者**。

      在限制模式中，不允許執行任務、停用偵錯、不套用工作區設定，以及延伸模組的功能有限。

      若要結束受限模式，請信任目前資料夾或其父資料夾中所有檔案的作者，並啟用所有功能，請在**受限模式**橫幅中選擇**管理**。

# 程式碼編輯器連線和延伸模組
<a name="code-editor-use-connections-and-extensions"></a>

Code Editor 支援與 的 IDE 連線 AWS 服務 ，以及 [Open VSX 登錄](https://open-vsx.org/)檔中可用的擴充功能。

## 與 的連線 AWS
<a name="code-editor-use-connections"></a>

程式碼編輯器環境已與 [AWS Toolkit for VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) 整合，以將連線新增至 AWS 服務。若要開始使用 的連線 AWS 服務，您必須擁有 valid AWS Identity and Access Management (IAM) 登入資料。如需詳細資訊，請參閱 [AWS Toolkit for Visual Studio Code 的身分驗證和存取](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/establish-credentials.html)。

在程式碼編輯器環境內，您可以將連線新增至：
+  [AWS Explorer ](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/aws-explorer.html) – 檢視、修改和部署 Amazon S3、CloudWatch 等 AWS 資源。

  在 AWS Explorer 中存取特定功能需要特定 AWS 許可。如需詳細資訊，請參閱 [AWS Toolkit for Visual Studio Code 的身分驗證和存取](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/establish-credentials.html)。
+ [Amazon CodeWhisperer](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/codewhisperer.html) - 使用採用 AI 技術的程式碼建議更快地建置應用程式。

  若要 Amazon CodeWhisperer 搭配程式碼編輯器使用 ，您必須將下列許可新增至 SageMaker AI 執行角色。

------
#### [ JSON ]

****  

  ```
  {
    "Version":"2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "CodeWhispererPermissions",
        "Effect": "Allow",
        "Action": ["codewhisperer:GenerateRecommendations"],
        "Resource": "*"
      }
    ]
  }
  ```

------

  如需詳細資訊，請參閱《IAM 使用者指南》**中的[建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)，以及[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

## 延伸模組
<a name="code-editor-use-extensions"></a>

程式碼編輯器支援 [Open VSX 登錄](https://open-vsx.org/)中可用的 IDE 延伸模組。

若要在程式碼編輯器環境中開始使用延伸模組，請選擇左側導覽窗格中的**延伸模組**圖示 (![\[Icon showing two overlapping squares representing multiple windows or instances.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-extensions-icon.png))。在這裡，您可以透過安裝 AWS 來設定 AWS 工具組的連線。如需詳細資訊，請參閱[安裝 AWS Toolkit for Visual Studio Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-toolkit.html)。

在搜尋列中，您可以透過 [Open VSX 登錄](https://open-vsx.org/)直接搜尋其他延伸模組，例如 AWS 工具組、Jupyter、Python 等。

# 關閉程式碼編輯器資源
<a name="code-editor-use-log-out"></a>

使用完程式碼編輯器空間時，您可以使用 Studio 來將其停止。如此一來，您就可以停止產生空間的成本。

或者，您可以使用 AWS CLI刪除未使用的程式碼編輯器資源。

## 使用 Studio 停止程式碼編輯器空間
<a name="code-editor-use-log-out-stop-space"></a>

若要在 Studio 中停止您的程式碼編輯器空間，請使用下列步驟：

**在 Studio 中停止您的程式碼編輯器空間**

1. 請執行下列其中一個動作，返回程式碼編輯器登陸頁面：

   1. 在左上角的導覽列中，選擇**程式碼編輯器**。

   1. 或者，在左側導覽窗格中，選擇**應用程式**功能表中的**程式碼編輯器**。

1. 尋找您建立的程式碼編輯器空間名稱。如果空間的狀態為**執行中**，請在**動作**欄中選擇**停止**。您也可以選擇**停止空間**，直接在空間詳細資訊頁面中停止空間。空間可能需要一些時間才能停止。

![\[程式碼編輯器應用程式 UI 中的空間詳細資訊頁面。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/code-editor/code-editor-stop-space.png)


當您的空間執行個體關閉時，不會自動刪除其他資源，例如 SageMaker AI 端點、Amazon EMR (Amazon EMR) 叢集，以及從 Studio 建立的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。若要停止從資源產生費用，請刪除任何其他資源。如需詳細資訊，請參閱[刪除未使用的資源](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-jl-admin-guide-clean-up.html)。

## 使用 刪除程式碼編輯器資源 AWS CLI
<a name="code-editor-use-log-out-shut-down-resources"></a>

您可以使用 AWS Command Line Interface () 刪除程式碼編輯器應用程式和空間AWS CLI。
+ [DeleteApp](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteApp.html)
+ [DeleteSpace](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteSpace.html)