

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

# 故障診斷 AWS Toolkit for Visual Studio Code
<a name="general-troubleshoot"></a>

下列各節包含有關 AWS Toolkit for Visual Studio Code 和從 工具組使用 AWS 服務的一般疑難排解資訊。如需 AWS 工具組中與疑難排解 SAM 問題特別相關的問題，請參閱《 使用者指南》中的[對無伺服器應用程式進行疑難排解](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-troubleshooting.html)主題。

**Topics**
+ [疑難排解最佳實務](#general-troubleshoot-best-practice)
+ [設定檔 ... 在組態檔案中找不到](#general-troubleshoot-profile-not-found)
+ [SAM json 結構描述：無法在 template.yaml 檔案中變更結構描述](#general-troubleshoot-sam-json-template-yaml)

## 疑難排解最佳實務
<a name="general-troubleshoot-best-practice"></a>

以下是疑難排解 AWS Toolkit for Visual Studio Code 問題時建議的最佳實務。如需如何貢獻 的詳細資訊 AWS Toolkit for Visual Studio Code，請參閱 AWS Toolkit for Visual Studio Code GitHub 儲存庫中的[貢獻主題 AWS Toolkit for Visual Studio Code](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md)。
+ 嘗試在傳送報告之前重新建立您的問題或錯誤。
+ 在重新建立過程中，記下每個步驟、設定和錯誤訊息的詳細記錄。
+ 收集您的 AWS Toolkit Debug Logs。如需如何尋找 AWS Toolkit Debug 日誌的詳細說明，請參閱本使用者指南主題中的*如何尋找 AWS 日誌*程序。
+ 檢查是否有開啟的請求、已知的解決方案，或在 AWS Toolkit for Visual Studio Code GitHub 儲存庫的問題區段中報告您未解決[AWS Toolkit for Visual Studio Code 的問題](https://github.com/aws/aws-toolkit-vscode/issues)。

**注意**  
下列程序說明如何檢視 AWS Toolkit Debug 日誌。檢視 Amazon Q Debug 日誌的程序完全相同，除非您從 VS Code Command Palette 選擇 **Amazon Q： 檢視日誌**。

**如何尋找 AWS Toolkit for Visual Studio Code 偵錯日誌**

1. 從 VS 程式碼中，按 **Cmd \+ Shift \+ P**或 **Ctrl \+ Shift \+ P**(Windows) **AWS View Logs**開啟命令調色盤，然後在搜尋欄位中輸入 。

1. 選擇**AWS 檢視日誌**以在 **VS 程式碼終端機輸出**視窗中開啟您的 AWS 工具組日誌。

1. 從 **VS 程式碼終端機輸出**視窗中，展開**齒輪**圖示功能表，然後選擇**偵錯**。

1. 再次展開**齒輪**圖示選單，然後選擇**設為預設**。

1. 按 **Cmd \+ Shift \+ P**或 **Ctrl \+ Shift \+ P**(Windows) 重新開啟命令調色盤，搜尋 **Reload Window**，然後選擇**開發人員：重新載入視窗**。

1. VS 程式碼會重新載入，而 **VS 程式碼終端機輸出**視窗會顯示您更新的 AWS Toolkit Debug 日誌。

## 設定檔 ... 在組態檔案中找不到
<a name="general-troubleshoot-profile-not-found"></a>

**問題**

**注意**  
此問題僅適用於 `~/.aws/config` 檔案，不適用於 `~/.aws/credentials` 檔案。如需組態和 AWS 登入資料檔案的詳細資訊，請參閱 SDK AWS 和*AWS 工具參考指南中的*[共用組態和登入資料檔案](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html)主題。

選擇登入資料時 AWS Toolkit 日誌會顯示具有此結構的訊息：`Profile name could not be found in shared credentials file`。

以下是 AWS Toolkit 日誌中此錯誤的外觀範例：

```
         2023-08-08 18:20:45 [ERROR]: _aws.auth.reauthenticate: Error: Unable to authenticate connection
         -> CredentialsProviderError: Profile vscode-prod-readonly could not be found in shared credentials file.
```

**解決方案**

如果您的設定檔已存在於 中`~/.aws/config`，請檢查其開頭是否為 `[profile `。以下是**正確**建構的使用者設定檔範例：

```
         [profile example]
         region=us-west-2
         credential_process=...
```

以下是**不正確**建構的使用者設定檔範例：

```
         [example]
         region=us-west-2
         credential_process=...
```

## SAM json 結構描述：無法在 template.yaml 檔案中變更結構描述
<a name="general-troubleshoot-sam-json-template-yaml"></a>

**問題**

您無法在 SAM template.yaml 中手動選取不同的 json 結構描述

**解決方案**

更新至 vscode-yaml 1.11\+ 版後，您可以在 YAML 檔案頂端新增**yaml-language-server**管制線，以強制 URI 使用結構描述。如需有關在 *Redhat 開發人員* GitHub 儲存庫的 *yaml 語言伺服器*主題中使用[內嵌結構描述](https://github.com/redhat-developer/yaml-language-server#using-inlined-schema)一節的詳細資訊。以下是**yaml-language-server**模式線的範例。

```
         # yaml-language-server: $schema=https://raw.githubusercontent.com/aws/serverless-application-model/main/samtranslator/schema/schema.json
```