

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

# 對無伺服器應用程式進行故障診斷
<a name="serverless-apps-troubleshooting"></a>

本主題詳細說明使用 Toolkit for VS 程式碼建立無伺服器應用程式時可能遇到的常見錯誤，以及如何解決這些錯誤。

**Topics**
+ [如何搭配 SAM 啟動組態使用 samconfig.toml？](#troubleshooting-samconfig-toml)
+ [錯誤：「RuntimeError：容器不存在」](#troubleshooting-container-does-not-exist)
+ [錯誤：「docker.errors.APIError：500 伺服器錯誤... 您已達到提取率限制。」](#troubleshooting-reached-rate-limit)
+ [錯誤：「500 伺服器錯誤：掛載 C：\$1Users\$1...」](#troubleshooting-mounting-error)
+ [使用 WSL 時，Webview （例如，「叫用 AWS」表單） 會中斷](#troubleshooting-broken-webviews)
+ [偵錯 TypeScript 應用程式，但中斷點無法運作](#troubleshooting-typescript-debugging)

## 如何搭配 SAM 啟動組態使用 samconfig.toml？
<a name="troubleshooting-samconfig-toml"></a>

在啟動組態的 `sam.localArguments` 屬性中設定 `--config-file`引數，以指定 SAM CLI [samconfig.toml](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html) 的位置。例如，如果 samconfig.toml 檔案位於工作區的最上層：

```
"sam": {
    "localArguments": ["--config-file", "${workspaceFolder}/samconfig.toml"],
}
```

## 錯誤：「RuntimeError：容器不存在」
<a name="troubleshooting-container-does-not-exist"></a>

如果您的系統沒有足夠的磁碟空間用於 Docker 容器，則 `sam build`命令可以顯示此錯誤。如果您的系統儲存體只有 1-2 GB 的可用空間， `sam build`可能會在處理期間失敗，即使系統儲存體在建置開始之前並未完全填滿。如需詳細資訊，請參閱[此 GitHub 問題](https://github.com/aws/aws-sam-cli/issues/2121)。

## 錯誤：「docker.errors.APIError：500 伺服器錯誤... 您已達到提取率限制。」
<a name="troubleshooting-reached-rate-limit"></a>

Docker Hub 會限制匿名使用者可以提出的請求。如果您的系統達到限制，Docker 失敗，且此錯誤會出現在 VS 程式碼的 OUTPUT 檢視中：

```
docker.errors.APIError: 500 Server Error: Internal Server Error ("toomanyrequests: You have
reached your pull rate limit. You may increase the limit by authenticating and upgrading:
https://www.docker.com/increase-rate-limit")
```

確保您的系統 Docker 服務已使用您的 Docker Hub 憑證進行身分驗證。

## 錯誤：「500 伺服器錯誤：掛載 C：\$1Users\$1...」
<a name="troubleshooting-mounting-error"></a>

Windows 使用者在偵錯 AWS SAM 應用程式時可能會看到此 Docker 掛載錯誤：

```
Fetching lambci/lambda:nodejs10.x Docker container image......
2019-07-12 13:36:58 Mounting C:\Users\<username>\AppData\Local\Temp\ ... as /var/task:ro,delegated inside runtime container
Traceback (most recent call last):
...
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error ...
```

嘗試重新整理共用磁碟機的登入資料 （在 Docker 設定中）。

## 使用 WSL 時，Webview （例如，「叫用 AWS」表單） 會中斷
<a name="troubleshooting-broken-webviews"></a>

這是 Cisco VPN 使用者的已知 VS 程式碼問題。如需詳細資訊，請參閱[此 GitHub 問題](https://github.com/aws/aws-toolkit-vscode/issues/1327)。

[此 WSL 追蹤問題](https://github.com/microsoft/WSL/issues/4277)建議解決方法。

## 偵錯 TypeScript 應用程式，但中斷點無法運作
<a name="troubleshooting-typescript-debugging"></a>

如果沒有將編譯的 JavaScript 檔案連結至來源 TypeScript 檔案的來源映射，就會發生這種情況。若要更正此問題，請開啟 `tsconfig.json` 檔案，並確保已設定下列選項和值：`"inlineSourceMap": true`。