

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

# 解決 Amazon ECS 已停止任務錯誤
<a name="resolve-stopped-errors"></a>

當任務無法啟動時，您會在主控台與 `describe-tasks` 輸出參數 (`stoppedReason` 與 `stopCode`) 中看到錯誤訊息。

您可於主控台中檢視已停止任務，檢視時效為一小時。若要檢視已停止任務，您必須變更篩選選項。如需詳細資訊，請參閱[檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

以下頁面會提供有關已停止任務的資訊。
+ 了解已停止任務錯誤訊息的變更。

  [Amazon ECS 已停止任務錯誤訊息更新](stopped-tasks-error-messages-updates.md)
+ 檢視已停止任務，取得相關錯誤成因資訊。

  [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)
+ 了解已停止任務錯誤訊息和可能的錯誤原因。

  [Amazon ECS 已停止任務錯誤訊息](stopped-task-error-codes.md)
+ 了解如何驗證已停止任的務連線狀態並修正錯誤。

  [驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)

# Amazon ECS 已停止任務錯誤訊息更新
<a name="stopped-tasks-error-messages-updates"></a>

自 2024 年 6 月 14 日起，Amazon ECS 團隊將變更已停止任務錯誤訊息，如下表所述。`stopCode` 不會變更。如果應用程式依賴確切的錯誤訊息字串，您必須使用新字串來更新應用程式。如需相關問題的協助，請聯絡 AWS 支援。

**注意**  
建議不要依賴自動化的錯誤訊息，因為錯誤訊息可能會有所變更。

## CannotPullContainerError
<a name="cannot-pull-container-error-changes"></a>


| 舊錯誤訊息 | 新錯誤訊息 | 
| --- | --- | 
| CannotPullContainerError: Error response from daemon: pull access denied for repository, repository does not exist or may require 'docker login': denied: User: roleARN | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/stopped-tasks-error-messages-updates.html)  | 
|  CannotPullContainerError: Error response from daemon: Get imageURI: net/http: request canceled while waiting for connection |  CannotPullContainerError: The task can’t pull the image. Check your network configuration. Error response from daemon: Get image: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) | 
| CannotPullContainerError: ref pull has been retried 5 time(s): failed to copy: httpReadSeeker: failed open: failed to do request: Get registry-uri: dial tcp <ip>:<port> i/o timeout | CannotPullContainerError: The task cannot pull image-uri from the registry registry-uri. There is a connection issue between the task and the registry. Check your task network configuration. : failed to copy: httpReadSeeker: failed open: failed to do request: Get registry-uri: dial tcp <ip>:<port> i/o timeout | 

## ResourceNotFoundException
<a name="resourcenotfound-error-changes"></a>


| 舊錯誤訊息 | 新錯誤訊息 | 
| --- | --- | 
| 從 AWS Secrets Manager 區域擷取秘密資料：秘密 sercretARN：ResourceNotFoundException：Secrets Manager 找不到指定的秘密。 | ResourceNotFoundException：任務無法從中擷取具有 ARN 'sercretARN' 的秘密 AWS Secrets Manager。Check whether the secret exists in the specified Region. ResourceNotFoundException：從 AWS Secrets Manager 區域擷取秘密資料：秘密 sercretARN：ResourceNotFoundException：Secrets Manager 找不到指定的秘密。 | 

## ResourceInitializationError
<a name="resourceinitialization-error-changes"></a>


| 舊錯誤訊息 | 新錯誤訊息 | 
| --- | --- | 
| ResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve ecr registry auth: service call has been retried 3 time(s): RequestError: send request failed caused by: Post "https://api.ecr.us-east-1.amazonaws.com/": dial tcp <ip>:<port>: i/o timeout. Please check your task network configuration. | ResourceInitializationError: unable to pull secrets or registry auth: The task cannot pull registry auth from Amazon ECR: There is a connection issue between the task and Amazon ECR. Check your task network configuration. RequestError: send request failed caused by: Post "https://api.ecr.us-east-1.amazonaws.com": dial tcp <ip>:<port>: i/o timeout | 
| ResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve secrets from ssm: service call has been retried 5 time(s): RequestCanceled: request context canceled caused by: context deadline exceeded | ResourceInitializationError: unable to pull secrets or registry auth: unable to retrieve secrets from ssm: The task cannot pull secrets from AWS Systems Manager. There is a connection issue between the task and AWS Systems Manager Parameter Store. Check your task network configuration. RequestCanceled: request context canceled caused by: context deadline exceeded | 
| ResourceInitializationError: failed to download env files: file download command: non empty error stream: RequestCanceled: request context canceled caused by: context deadline exceeded | ResourceInitializationError: failed to download env files: The task can't download the environment variable files from Amazon S3. There is a connection issue between the task and Amazon S3. Check your task network configuration. service call has been retried 5 time(s): RequestCanceled: request context canceled caused by: context deadline exceeded | 
| ResourceInitializationError: failed to validate logger args::signal:killed | ResourceInitializationError: failed to validate logger args: The task cannot find the Amazon CloudWatch log group defined in the task definition. There is a connection issue between the task and Amazon CloudWatch. Check your network configuration. : signal: killed | 
| ResourceInitializationError: unable to pull secrets or registry auth: pull command failed: : signal: killed | ResourceInitializationError: unable to pull secrets or registry auth: Check your task network configuration. : signal: killed | 

# 檢視 Amazon ECS 已停止任務錯誤
<a name="stopped-task-errors"></a>

如果啟動任務時有問題，您的任務可能會因為應用程式或組態錯誤而停止。例如，您執行任務，而任務顯示 `PENDING` 狀態，然後就消失。

 如果您的任務是由 Amazon ECS 服務建立，Amazon ECS 為維護服務所採取的動作會發佈在服務事件中。您可以在 AWS 管理主控台、 AWS CLI、 AWS SDKs、Amazon ECS API 或使用 SDKs 和 API 的工具中檢視事件。這些事件包括 Amazon ECS 停止並取代任務，因為任務中的容器已停止執行，或多次未通過 Elastic Load Balancing 的運作狀態檢查。

如果任務在 Amazon EC2 或外部電腦的容器執行個體上執行，您也可以檢視容器執行時期與 Amazon ECS 代理程式的日誌。這些日誌位於主機 Amazon EC2 執行個體或外部電腦上。如需詳細資訊，請參閱[檢視 Amazon ECS 容器代理程式日誌](logs.md)。

## 程序
<a name="view-stopped-errors-procedure"></a>

------
#### [ Console ]

**AWS 管理主控台**

您可透過主控台按下列步驟來檢查已停止任務是否有錯誤。若要檢視已停止任務，您必須變更篩選選項。

已停止任務只會在主控台中顯示 1 小時。

1. 開啟主控台，網址為 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2)。

1. 在導覽窗格中，選擇**叢集**。

1. 在**叢集**頁面上，選擇叢集。

1. 在 **Cluster : *name*** (叢集：名稱) 頁面上，選擇 **Tasks** (任務) 索引標籤。

1. 設定篩選條件以顯示已停止的任務。在**篩選所需狀態**欄位中選擇**已停止**。

   **Stopped** (已停止) 選項會顯示已停止的任務，而 **Any desired status** (任何所需狀態) 會顯示所有任務。

1. 選擇要檢查的已停止任務。

1. 在已停止任務的列中，在 **Last Status** (上次狀態) 欄中，選擇 **Stopped** (已停止)。

   快顯視窗隨即顯示停止原因。

------
#### [ AWS CLI ]

1. 列出叢集中停止的任務。輸出包含任務的 Amazon Resource Name (ARN)，您需要 Amazon Resource Name (ARN) 來描述任務。

   ```
   aws ecs list-tasks \
        --cluster cluster_name \
        --desired-status STOPPED \
        --region region
   ```

1. 描述已停止任務以擷取資訊。如需詳細資訊，請參閱《 * AWS Command Line Interface 參考*》中的 [describe-tasks](https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-tasks.html)。

   ```
   aws ecs describe-tasks \
        --cluster cluster_name \
        --tasks arn:aws:ecs:region:account_id:task/cluster_name/task_ID \
        --region region
   ```

使用下列輸出參數。
+ `stopCode` – 停止代碼會指出任務停止的原因，例如 ResourceInitializationError
+ `StoppedReason` – 任務停止的原因。
+ `reason` (在 `containers` 結構中) – 原因會提供已停止容器的額外詳細資訊。

------

## 後續步驟
<a name="additional-resources"></a>

檢視已停止任務，取得相關錯誤成因資訊。如需詳細資訊，請參閱[Amazon ECS 已停止任務錯誤訊息](stopped-task-error-codes.md)。

# Amazon ECS 已停止任務錯誤訊息
<a name="stopped-task-error-codes"></a>

以下是任務意外停止時，可能會收到的錯誤訊息。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

**提示**  
您可以[Amazon ECS MCP 伺服器](ecs-mcp-introduction.md)搭配 AI 助理使用 ，以自然語言分析任務失敗和容器日誌。

已停止任務錯誤代碼具有與其相關聯的類別，例如 "ResourceInitializationError"。如需了解每個類別的詳細資訊，請參閱下列主題：


| Category | 進一步了解 | 
| --- | --- | 
|  TaskFailedToStart  |  [對 Amazon ECS TaskFailedToStart 錯誤進行疑難排解](failed-to-start-error.md)  | 
|  ResourceInitializationError  |  [對 Amazon ECS ResourceInitializationError 錯誤進行疑難排解](resource-initialization-error.md)  | 
| ResourceNotFoundException |  [對 Amazon ECS ResourceNotFoundException 錯誤進行疑難排解](resource-not-found-error.md) | 
|  SpotInterruptionError  |  [對 Amazon ECS SpotInterruption 錯誤進行疑難排解](spot-interruption-errors.md)  | 
|  InternalError  |  [對 Amazon ECS InternalError 錯誤進行疑難排解](internal-error.md)  | 
|  OutOfMemoryError  |  [對 Amazon ECS OutOfMemoryError 錯誤進行疑難排解](out-of-memory.md)  | 
|  ContainerRuntimeError  |  [對 Amazon ECS ContainerRuntimeError 錯誤進行疑難排解](container-runtime-error.md)  | 
|  ContainerRuntimeTimeoutError  |  [對 Amazon ECS ContainerRuntimeTimeoutError 錯誤進行疑難排解](container-runtime-timeout-error.md)  | 
|  CannotStartContainerError  |  [對 Amazon ECS CannotStartContainerError 錯誤進行疑難排解](cannot-start-container.md)  | 
|  CannotStopContainerError  |  [對 Amazon ECS CannotStopContainerError 錯誤進行疑難排解](cannot-stop-container.md)  | 
|  CannotInspectContainerError  |  [對 Amazon ECS CannotInspectContainerError 錯誤進行疑難排解](cannot-inspect-container.md)  | 
|  CannotCreateVolumeError  |  [對 Amazon ECS CannotCreateVolumeError 錯誤進行疑難排解](cannot-create-volume.md)  | 
| CannotPullContainer |  [Amazon ECS 中的 CannotPullContainer 任務錯誤](task_cannot_pull_image.md)  | 

# 對 Amazon ECS TaskFailedToStart 錯誤進行疑難排解
<a name="failed-to-start-error"></a>

以下是部分 `TaskFailedToStart` 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## 嘗試在子網路 *subnet-id* 中建立啟用了公有 IP 指派的網路介面時，發生意外 EC2 錯誤
<a name="subnet-error"></a>

當 Fargate 任務使用 `awsvpc` 網路模式並在具有公有 IP 位址的子網路中執行，且子網路沒有足夠的 IP 位址時，就會發生這種情況。

可在 Amazon EC2 主控台的子網路詳細資訊頁面上檢視可用 IP 位址的數量，也可透過 `[describe-subnets](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-subnets.html)` 檢視該數量。如需詳細資訊，請參閱 *Amazon VPC User Guide* 中的 [View your subnet](https://docs.aws.amazon.com/vpc/latest/userguide/working-with-vpcs.html#view-subnet)。

若要修正此問題，您可以建立新的子網路，在其中執行任務。

## InternalError: *<reason>*
<a name="internal-error-reason"></a>

在請求 ENI 附件時，會發生此錯誤。Amazon EC2 以非同步方式處理 ENI 的佈建。佈建程序需要時間。Amazon ECS 會出現逾時，導致等待時間較長或未報告的故障。有時會佈建 ENI，但報告會在故障逾時後傳送給 Amazon ECS。在這種情況下，Amazon ECS 會透過使用中的 ENI 查看報告的任務失敗。

## 選取的任務定義與選取的運算策略不相容
<a name="compute-compatibility"></a>

當您選擇啟動類型不符合叢集容量類型的任務定義時，就會發生此錯誤。您需要選取與指派給叢集的容量提供者相符的任務定義。

## 無法將網路介面連接至閒置的裝置索引
<a name="compute-compatibility-cpu"></a>

使用 `awsvpc` 聯網類型且任務沒有足夠的 CPU/記憶體時，即會發生此錯誤。首先，檢查執行個體的 CPU。如需詳細資訊，請參閱 *Amazon EC2 instance types* 中的 [Amazon EC2 instance type specifications](https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-instance-type-specifications.html) 。取執行個體的 CPU 值，並將其乘以執行個體 ENI 數量。在任務定義中使用值 e。

## 代理程式
<a name="agent-not-started"></a>

您嘗試啟動任務所在之容器執行個體上的代理程式目前中斷連線。為避免延長任務置放等待時間，請求遭到拒絕。

如需如何對已中斷連線的代理程式進行故障診斷的相關資訊，請參閱 [How do I troubleshoot a disconnected Amazon ECS agent](https://repost.aws/knowledge-center/ecs-agent-disconnected-linux2-ami) (如何對已中斷連線的 Amazon ECS 代理程式進行故障診斷)。

# 對 Amazon ECS ResourceInitializationError 錯誤進行疑難排解
<a name="resource-initialization-error"></a>

以下是部分 `ResourceInitialization` 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

**Topics**
+ [The task cannot pull registry authentication from Amazon ECR. There is a connection issue between the task and Amazon ECR. Check your task network configuration.](#unable-to-pull-secrets-ecr)
+ [The task can't download the environment variable files from Amazon S3. There is a connection issue between the task and Amazon S3. Check your task network configuration.](#failed-to-download-env-files)
+ [任務無法從 AWS Systems Manager 參數存放區提取秘密。檢查任務與 之間的網路連線 AWS Systems Manager。](#unable-to-pull-secrets-sys-manager)
+ [任務無法從中提取秘密 AWS Secrets Manager。There is a connection issue between the task and Secrets Manager. Check your task network configuration.](#unable-to-pull-secrets-asm-no-arn)
+ [The task can’t pull the secret from Secrets Manager. The task can't retrieve the secret with ARN ‘*secretARN*' from Secrets Manager. Check whether the secret exists in the specified Region.](#unable-to-pull-secrets-asm)
+ [pull command failed: unable to pull secrets or registry auth Check your task network configuration.](#pull-command-failed)
+ [任務找不到任務定義中所定義的 Amazon CloudWatch 日誌群組。There is a connection issue between the task and Amazon CloudWatch. Check your network configuration.](#failed-to-initialize-logging-network)
+ [failed to initialize logging driver](#failed-to-initialize-logging)
+ [無法調用 EFS utils 命令來設定 EFS 磁碟區](#efs-utils-failed)

## The task cannot pull registry authentication from Amazon ECR. There is a connection issue between the task and Amazon ECR. Check your task network configuration.
<a name="unable-to-pull-secrets-ecr"></a>

此錯誤表示任務無法連線至 Amazon ECR。

檢查任務與 Amazon ECR 之間的連線。如需相關資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## The task can't download the environment variable files from Amazon S3. There is a connection issue between the task and Amazon S3. Check your task network configuration.
<a name="failed-to-download-env-files"></a>

當任務無法從 Amazon S3 下載環境檔案時，就會發生此錯誤。

檢查任務與 Amazon S3 VPC 端點之間的連線。如需相關資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## 任務無法從 AWS Systems Manager 參數存放區提取秘密。檢查任務與 之間的網路連線 AWS Systems Manager。
<a name="unable-to-pull-secrets-sys-manager"></a>

當任務無法使用 Systems Manager 中的憑證提取任務定義中定義的映像時，就會發生此錯誤。

檢查任務與 Systems Manager VPC 端點之間的連線。如需相關資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## 任務無法從中提取秘密 AWS Secrets Manager。There is a connection issue between the task and Secrets Manager. Check your task network configuration.
<a name="unable-to-pull-secrets-asm-no-arn"></a>

當任務無法使用 Secrets Manager 中的憑證提取任務定義中定義的映像時，就會發生此錯誤。

此錯誤表示 Systems Manager VPC 端點與任務之間存在網路連線問題。

如需有關如何驗證任務與端點之間連線的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## The task can’t pull the secret from Secrets Manager. The task can't retrieve the secret with ARN ‘*secretARN*' from Secrets Manager. Check whether the secret exists in the specified Region.
<a name="unable-to-pull-secrets-asm"></a>

當任務無法使用 Secrets Manager 中的憑證提取任務定義中定義的映像時，就會發生此錯誤。

此問題由以下其中一個原因造成：


| 錯誤原因... | 執行此作業... | 
| --- | --- | 
|   Secrets Manager VPC 端點與任務之間存在網路連線問題。 在錯誤訊息中看到下列任何字串時，表示存在網路問題： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/resource-initialization-error.html)  |  驗證任務與 Secrets Manager 端點之間的連線狀態。如需詳細資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。  | 
| 任務定義中所定義的任務執行角色，沒有 Secrets Manager 所需的許可。 |  將 Secrets Manager 所需的許可新增至任務執行角色。如需詳細資訊，請參閱[Secrets Manager 或 Systems Manager 許可](task_execution_IAM_role.md#task-execution-secrets)。  | 
| 秘密 ARN 不存在 | 檢查 Secrets Manager 中是否存在 ARN。如需有關檢視映像的資訊，請參閱 Secrets Manager Developer Guide 中的 [Find secrets in Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_search-secret.html)。 | 

## pull command failed: unable to pull secrets or registry auth Check your task network configuration.
<a name="pull-command-failed"></a>

當任務無法連線至 Amazon ECR、Systems Manager 或 Secrets Manager 時，就會發生此錯誤。此問題源自於網路組態錯誤。

若要修正此問題，請驗證任務與 Amazon ECR 之間的連線狀態。您也需要檢查任務與儲存秘密的服務 (Systems Manager 或 Secrets Manager) 之間的連線狀態。如需詳細資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## 任務找不到任務定義中所定義的 Amazon CloudWatch 日誌群組。There is a connection issue between the task and Amazon CloudWatch. Check your network configuration.
<a name="failed-to-initialize-logging-network"></a>

當任務找不到您在任務定義中定義的 CloudWatch 日誌群組時，就會發生此錯誤。

此錯誤表示 CloudWatch VPC 端點與任務之間存在網路連線問題。

如需有關如何驗證任務與端點之間連線的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## failed to initialize logging driver
<a name="failed-to-initialize-logging"></a>

當任務找不到您在任務定義中定義的 CloudWatch 日誌群組時，就會發生此錯誤。

此錯誤表示任務定義中的 CloudWatch 群組不存在。

使用下列步驟尋找缺少的 CloudWatch。

1. 執行下列命令來取得任務定義資訊。

   ```
   aws ecs describe-task-definition \ 
       --task-definition task-def-name
   ```

   查看每個容器的輸出，並記下 `awslogs-group` 值。

   ```
   "logConfiguration": {
                   "logDriver": "awslogs",
                   "options": {
                       "awslogs-group": "/ecs/example-group",
                       "awslogs-create-group": "true",
                       "awslogs-region": "us-east-1",
                       "awslogs-stream-prefix": "ecs"
                   },
   ```

1. 確認群組存在於 CloudWatch 中。如需詳細資訊，請參閱 *Amazon CloudWatch Logs User Guide* 中的 [Working with log groups and log streams](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html)。

   問題可能是任務定義中指定的群組不正確，也可能是日誌群組不存在。

1. 修正問題。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/resource-initialization-error.html)

## 無法調用 EFS utils 命令來設定 EFS 磁碟區
<a name="efs-utils-failed"></a>

下列問題可能會阻止您在任務上掛載 Amazon EFS 磁碟區：
+ Amazon EFS 檔案系統設定不正確。
+ 任務缺少必要許可。
+ 存在與網路與 VPC 組態相關的問題。

 如需有關如何偵錯和修正此問題的資訊，請參閱[為何我無法在 re：Post 上的 AWS Fargate 任務上掛載 Amazon EFS 磁碟區](https://repost.aws/knowledge-center/fargate-unable-to-mount-efs)。 AWS 

# 對 Amazon ECS ResourceNotFoundException 錯誤進行疑難排解
<a name="resource-not-found-error"></a>

以下是部分 ` ResourceNotFoundException` 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## 任務無法從中擷取具有 ARN '*sercretARN*' 的秘密 AWS Secrets Manager。Check whether the secret exists in the specified Region.
<a name="unable-to-pull-secrets-ecr"></a>

當任務無法從 Secrets Manager 擷取秘密時，就會發生此錯誤。這表示在任務定義中指定 (並且在錯誤訊息中包含) 的秘密不存在於 Secrets Manager 中。

區域資訊包含在錯誤訊息中。

從 AWS Secrets Manager *區域*擷取秘密資料：秘密 *sercretARN*：ResourceNotFoundException：Secrets Manager 找不到指定的秘密。

如需有關尋找秘密的資訊，請參閱 *AWS Secrets Manager User Guide* 中的 [Find secrets in AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_search-secret.html)。

使用下表來判斷並解決錯誤。


| 問題 | 動作 | 
| --- | --- | 
| 秘密位於與任務定義不同的區域。 |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/resource-not-found-error.html) | 
| 任務定義的秘密 ARN 不正確。Secrets Manager 中存在正確的秘密。 | 使用正確的秘密更新任務定義。如需詳細資訊，請參閱[使用主控台更新 Amazon ECS 任務定義](update-task-definition-console-v2.md)，或 Amazon Elastic Container Service API Reference 中的 [RegisterTaskDefinition](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RegisterTaskDefinition.html)。 | 
| 秘密不再存在。 |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/resource-not-found-error.html)  | 

# 對 Amazon ECS SpotInterruption 錯誤進行疑難排解
<a name="spot-interruption-errors"></a>

`SpotInterruption` 錯誤在 Fargate 和 EC2 中發生的原因不相同。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## Fargate
<a name="fargate-spot-error"></a>

當沒有 Fargate Spot 容量或當 Fargate 取回 Spot 容量時，就會發生 `SpotInterruption` 錯誤。

您可以讓任務在多個可用區域中執行，以取得更多容量。

## EC2
<a name="ec2-spot-error"></a>

當沒有可用的 Spot 執行個體或當 EC2 取回 Spot 執行個體容量時，就會發生此錯誤。

您可以讓執行個體在多個可用區域中執行，以取得更多容量。

# 對 Amazon ECS InternalError 錯誤進行疑難排解
<a name="internal-error"></a>

**適用對象**：Fargate

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

當代理程式遇到非執行時期相關的意外內部錯誤時，就會發生 `InternalError` 錯誤。

只有在使用平台版本 `1.4` 或更新版本時，才會發生此錯誤。

如需有關偵錯和修正此問題的資訊，請參閱 [Amazon ECS 已停止任務錯誤訊息](stopped-task-error-codes.md)。

# 對 Amazon ECS OutOfMemoryError 錯誤進行疑難排解
<a name="out-of-memory"></a>

以下是部分 OutOfMemoryError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## container killed due to memory usage
<a name="container-memory-usage"></a>

當容器結束是由於容器中的程序消耗的記憶體比任務定義中分配的記憶體更多時，或是由於主機或作業系統限制時，就會發生此錯誤。

# 對 Amazon ECS ContainerRuntimeError 錯誤進行疑難排解
<a name="container-runtime-error"></a>

以下是部分 ContainerRuntimeError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## ContainerRuntimeError
<a name="container-runtime-error-1"></a>

當代理程式從 `containerd` 接收到特定執行時間操作的意外錯誤時，會發生此錯誤。此錯誤通常是由代理程式或 `containerd` 執行時間的內部失敗所造成。

只有在使用平台版本 `1.4.0` 或更新版本 (Linux)，或 `1.0.0` 或更新版本 (Windows) 時，才會發生此錯誤。

如需有關如何偵錯和修正此問題的資訊，請參閱[為什麼我的 Amazon ECS 任務在 re：Post 上停止](https://repost.aws/knowledge-center/ecs-task-stopped)。 AWS 

# 對 Amazon ECS ContainerRuntimeTimeoutError 錯誤進行疑難排解
<a name="container-runtime-timeout-error"></a>

以下是部分 ContainerRuntimeTimeoutError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## Could not transition to running; timed out after waiting 1m or Docker timeout error
<a name="container-runtime-timeout-error-1"></a>

當容器在逾時期間無法轉換成 `RUNNING` 或 `STOPPED` 狀態時，會發生此錯誤。錯誤訊息中會提供原因和逾時值。

# 對 Amazon ECS CannotStartContainerError 錯誤進行疑難排解
<a name="cannot-start-container"></a>

以下是部分 CannotStartContainerError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## failed to get container status: *<reason>*
<a name="cannot-start-container-1"></a>

無法啟動容器時，會發生此錯誤。

如果容器嘗試使用超過此處指定的記憶體，容器便會終止。增加分配給容器的記憶體。這是任務定義中的 `memory` 參數。如需詳細資訊，請參閱[記憶體](task_definition_parameters.md#container_definition_memory)。

# 對 Amazon ECS CannotStopContainerError 錯誤進行疑難排解
<a name="cannot-stop-container"></a>

以下是部分 CannotStopContainerError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## CannotStopContainerError
<a name="cannot-stop-container-1"></a>

無法停用容器時，會發生此錯誤。

如需有關如何偵錯和修正此問題的資訊，請參閱[為什麼我的 Amazon ECS 任務在 re：Post 上停止](https://repost.aws/knowledge-center/ecs-task-stopped)。 AWS 

# 對 Amazon ECS CannotInspectContainerError 錯誤進行疑難排解
<a name="cannot-inspect-container"></a>

以下是部分 CannotInspectContainerError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## CannotInspectContainerError
<a name="cannot-inspect-container-1"></a>

當容器代理程式無法透過容器執行時間描述容器時，會發生此錯誤。

使用平台版本 `1.3` 或先前版本時，Amazon ECS 代理程式會從 Docker 傳回原因。

使用平台版本 `1.4.0` 或更新版本 (Linux)，或者 `1.0.0` 或更新版本 (Windows) 時，Fargate 代理程式會從 `containerd` 傳回原因。

如需有關如何偵錯和修正此問題的資訊，請參閱[為什麼我的 Amazon ECS 任務在 re：Post 上停止](https://repost.aws/knowledge-center/ecs-task-stopped)。 AWS 

# 對 Amazon ECS CannotCreateVolumeError 錯誤進行疑難排解
<a name="cannot-create-volume"></a>

以下是部分 CannotCreateVolumeError 錯誤訊息以及可採取的錯誤修正動作。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

## CannotCreateVolumeError
<a name="cannot-create-volume-1"></a>

當代理程式無法建立任務定義中指定的磁碟區掛載時，會發生此錯誤。

只有在使用平台版本 `1.4.0` 或更新版本 (Linux)，或 `1.0.0` 或更新版本 (Windows) 時，才會發生此錯誤。

如需有關如何偵錯和修正此問題的資訊，請參閱[為什麼我的 Amazon ECS 任務在 re：Post 上停止](https://repost.aws/knowledge-center/ecs-task-stopped)。 AWS 

# Amazon ECS 中的 CannotPullContainer 任務錯誤
<a name="task_cannot_pull_image"></a>

下列錯誤表示任務無法啟動，因為 Amazon ECS 無法擷取指定的容器映像。

**注意**  
1.4 Fargate 平台版本會截斷長的錯誤訊息。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

**提示**  
您可以[Amazon ECS MCP 伺服器](ecs-mcp-introduction.md)搭配 AI 助理使用 ，使用自然語言調查影像提取錯誤。

**Topics**
+ [The task can’t pull the image. Check that the role has the permissions to pull images from the registry.](#pull-request-image-not-found)
+ [The task cannot pull ‘*image-name*’ from the Amazon ECR repository ‘*repository URI*’. There is a connection issue between the task and Amazon ECR. Check your task network configuration.](#pull-image-io-timeout)
+ [The task can’t pull the image. Check your network configuration](#pull-request-image-not-found-network)
+ [CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref](#pull-request-image-tag)
+ [API error (500): Get https://111122223333.dkr.ecr.us-east-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection](#request-canceled)
+ [API 錯誤](#pull-request-api-error)
+ [write /var/lib/docker/tmp/*GetImageBlob111111111*: no space left on device](#pull-request-write-error)
+ [ERROR: toomanyrequests: Too Many Requests or You have reached your pull rate limit.](#container-pull-too-many-requests)
+ [Error response from daemon: Get *url*: net/http: request canceled while waiting for connection](#container-pull-request-canceled-connection)
+ [ref pull has been retried 1 time(s): failed to copy: httpReaderSeeker: failed open: unexpected status code](#container-pull-failed-open)
+ [pull access denied](#container-pull-access-denied.title)
+ [pull command failed: panic: runtime error: invalid memory address or nil pointer dereference](#container-pull-runtime-error.title)
+ [error pulling image conf/error pulling image configuration](#container-pull-pulling-image.title)
+ [內容已取消](#container-pull-context-canceled)

## The task can’t pull the image. Check that the role has the permissions to pull images from the registry.
<a name="pull-request-image-not-found"></a>

此錯誤表示由於許可問題，任務無法提取任務定義中指定的映像。

若要解決此問題：

1. 檢查映像是否存在於*儲存庫*中。如需有關檢視映像的資訊，請參閱 *Amazon Elastic Container Registry User Guide* 中的 [Viewing image details in Amazon ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-info.html)。

1. 確認 *role-arn* 具有提取映像的正確許可。

   如需有關如何更新角色的資訊，請參閱 *AWS Identity and Access Management Use Guide* 中的 [Update permissions for a role](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-permissions.html)。

   任務使用以下任一角色：
   + 對於使用 Fargate 的任務，此為任務執行角色。如需有關 Amazon ECR 額外許可的資訊，請參閱 [Fargate 任務透過介面端點提取 Amazon ECR 映像的許可](task_execution_IAM_role.md#task-execution-ecr-conditionkeys)。
   + 對於使用 EC2 的任務，此為容器執行個體角色。如需有關 Amazon ECR 額外許可的資訊，請參閱 [Amazon ECR 許可](instance_IAM_role.md#container-instance-role-ecr)。

## The task cannot pull ‘*image-name*’ from the Amazon ECR repository ‘*repository URI*’. There is a connection issue between the task and Amazon ECR. Check your task network configuration.
<a name="pull-image-io-timeout"></a>

此錯誤表示任務無法連線至 Amazon ECR。檢查*儲存庫 URI* 儲存庫的連線。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## The task can’t pull the image. Check your network configuration
<a name="pull-request-image-not-found-network"></a>

此錯誤表示任務無法連線至 Amazon ECR。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref
<a name="pull-request-image-tag"></a>

此錯誤表示任務無法提取映像。

若要解決此問題，您可以：
+ 確認任務定義中指定的映像符合儲存庫中的映像。
+ Amazon ECS 會強制保障映像版本穩定性。若原始映像不再可用，您就會遇到此錯誤。映像標籤是強制實施此項機制的關鍵組成。請將任務定義中的映像標籤從 :latest 更改為特定版本。如需詳細資訊，請參閱[容器映像解析](deployment-type-ecs.md#deployment-container-image-stability)。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## API error (500): Get https://111122223333.dkr.ecr.us-east-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection
<a name="request-canceled"></a>

此錯誤表示連線已逾時，原因是不存在通往網際網路的路由。

要解決此問題，則可以採取下列方式：
+ 針對公有子網路中的任務，您必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **ENABLED** (啟用)。如需詳細資訊，請參閱[將應用程式作為 Amazon ECS 任務執行](standalone-task-create.md)。
+ 針對在私有子網路中的任務，則必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **DISABLED** (停用)，並設定 VPC 中的 NAT 閘道，以便將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [NAT 閘道](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。

## API 錯誤
<a name="pull-request-api-error"></a>

此錯誤表示 Amazon ECR 端點存在連線問題。

如需如何解決此問題的資訊，請參閱 支援 網站上的[如何解決 Amazon ECS 中的 Amazon ECR 錯誤「CannotPullContainerError： API 錯誤」](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-api-error-ecr/)。

## write /var/lib/docker/tmp/*GetImageBlob111111111*: no space left on device
<a name="pull-request-write-error"></a>

此錯誤表示磁碟空間不足。

若要解決這個問題，請釋放磁碟空間。

如果使用 Amazon ECS 最佳化 AMI，您可以透過下列命令來擷取檔案系統上最大的前 20 個檔案：

```
du -Sh / | sort -rh | head -20
```

輸出範例：

```
5.7G    /var/lib/docker/containers/50501b5f4cbf90b406e0ca60bf4e6d4ec8f773a6c1d2b451ed8e0195418ad0d2
1.2G    /var/log/ecs
594M    /var/lib/docker/devicemapper/mnt/c8e3010e36ce4c089bf286a623699f5233097ca126ebd5a700af023a5127633d/rootfs/data/logs
...
```

在某些情況下，執行容器可能會填滿根磁碟區。如果容器使用預設的 `json-file` 日誌驅動程式，而不具有 `max-size` 限制，則該日誌檔案可能佔用大部分空間。您可以使用 `docker ps` 命令，透過將目錄名稱從上面的輸出映射至容器 ID，來驗證哪個容器正在使用該空間。例如：

```
CONTAINER ID   IMAGE                            COMMAND             CREATED             STATUS              PORTS                            NAMES
50501b5f4cbf   amazon/amazon-ecs-agent:latest   "/agent"            4 days ago          Up 4 days                                            ecs-agent
```

在預設情況下，當使用 `json-file` 日誌驅動程式時，Docker 會擷取所有容器的標準輸出 (和標準錯誤)，並使用 JSON 格式將其寫入檔案中。您可以將 `max-size` 設定為日誌驅動程式選項，以防止日誌檔案佔用過多空間。如需詳細資訊，請參閱 Docker 文件中的 [JSON File logging driver](https://docs.docker.com/engine/logging/drivers/json-file/)。

下列是一個容器定義片段，顯示如何使用此選項：

```
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "256m"
    }
}
```

如果容器日誌佔用太多磁碟空間，則可使用 `awslogs` 日誌驅動程式。`awslogs` 日誌驅動程式會將日誌傳送至 CloudWatch，以釋放原本要給容器執行個體上的容器日誌使用的磁碟空間。如需詳細資訊，請參閱[將 Amazon ECS 日誌傳送至 CloudWatch](using_awslogs.md)。

您可能需要更新 Docker 可存取的磁碟大小。

如需詳細資訊，請參閱 [CannotPullContainerError: no space left on device](https://repost.aws/questions/QUx6Ix1R1SSNisYSs1Sw8EBA/cannotpullcontainererror-no-space-left-on-device)。

## ERROR: toomanyrequests: Too Many Requests or You have reached your pull rate limit.
<a name="container-pull-too-many-requests"></a>

此錯誤表示存在 Docker Hub 速率限制。

如果收到下列其中一項錯誤訊息，您很可能會達到 Docker Hub 速率限制：

如需 Docker Hub 速率限制的詳細資訊，請參閱[了解 Docker Hub 速率限制](https://www.docker.com/increase-rate-limits)。

如果您已提升 Docker Hub 速率限制，並且需要身分驗證容器執行個體的 Docker 提取，請參閱[容器執行個體的私有登錄檔身分驗證](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/private-auth-container-instances.html)。

## Error response from daemon: Get *url*: net/http: request canceled while waiting for connection
<a name="container-pull-request-canceled-connection"></a>

此錯誤表示連線已逾時，原因是不存在通往網際網路的路由。

要解決此問題，則可以採取下列方式：
+ 針對公有子網路中的任務，您必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **ENABLED** (啟用)。如需詳細資訊，請參閱[將應用程式作為 Amazon ECS 任務執行](standalone-task-create.md)。
+ 針對在私有子網路中的任務，則必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **DISABLED** (停用)，並設定 VPC 中的 NAT 閘道，以便將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [NAT 閘道](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。

## ref pull has been retried 1 time(s): failed to copy: httpReaderSeeker: failed open: unexpected status code
<a name="container-pull-failed-open"></a>

此錯誤表示複製映像時失敗。

若要解決此問題，請檢閱下列文章：
+ 如需 Fargate 任務，請參閱[如何解決 Fargate 上 Amazon ECS 任務的 "cannotpullcontainererror" 錯誤](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-pull-container-error/)。
+ 如需其他任務，請參閱[如何解決 Fargate 上 Amazon ECS 任務的 "cannotpullcontainererror" 錯誤](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-error/)。

## pull access denied
<a name="container-pull-access-denied.title"></a>

此錯誤表示無法存取映像。

若要解決此問題，您可能需要使用 Amazon ECR 驗證 Docker 用戶端。如需詳細資訊，請參閱 *Amazon ECR User Guide* 中的 [Private registry authentication](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html)。

## pull command failed: panic: runtime error: invalid memory address or nil pointer dereference
<a name="container-pull-runtime-error.title"></a>

此錯誤表示由於記憶體位址無效或空指標解除參照，無法存取映像。

若要解決此問題：
+ 檢查您是否擁有可連接 Amazon S3 的安全群組規則。
+ 使用閘道端點時，必須在路由表中新增路由，才能存取端點。

## error pulling image conf/error pulling image configuration
<a name="container-pull-pulling-image.title"></a>

此錯誤表示已達到速率限制或發生網路錯誤：

若要解決此問題，請參閱[我的 Amazon ECS EC2 啟動類型任務中的如何解決「CannotPullContainerError」錯誤](https://repost.aws/knowledge-center/ecs-pull-container-error)。

## 內容已取消
<a name="container-pull-context-canceled"></a>

此錯誤表示內容已取消。

此錯誤的原因通常是因為您的任務所使用的 VPC 沒有路由，而無法從 Amazon ECR 提取容器映像。

# 驗證 Amazon ECS 已停止任務的連線狀態
<a name="verify-connectivity"></a>

有時候任務會因為網路連線問題而停止。這可能是間歇性問題，但最有可能是因為任務無法連線至端點。

## 測試任務連線狀態
<a name="test-network"></a>

您可以使用 `AWSSupport-TroubleshootECSTaskFailedToStart` 執行手冊來測試任務連線狀態。在使用執行手冊時，您需要下列資源資訊：
+ 任務 ID

  使用最近失敗任務的 ID。
+ 任務所在的叢集

如需有關如何使用執行手冊的資訊，請參閱 *AWS Systems Manager Automation runbook reference* 中的 [https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-aws-troubleshootecstaskfailedtostart.html](https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-aws-troubleshootecstaskfailedtostart.html)。

執行手冊會分析任務。您可以在**輸出**區段中檢視下列問題的結果，這些問題可能會阻止任務啟動：
+ 與已設定容器登錄檔的網路連線
+ VPC 端點連線
+ 安全群組規則組態

## 修正 VPC 端點問題
<a name="fix-vpc-endpoints"></a>

當 `AWSSupport-TroubleshootECSTaskFailedToStart` 執行手冊結果顯示存在 VPC 端點問題時，請檢查下列組態：
+ 建立端點的 VPC 和 VPC 端點需要使用私有 DNS。
+ 請確定您有一個 服務的 AWS PrivateLink 端點，而任務無法在與任務相同的 VPC 中連線到該端點。如需詳細資訊，請參閱下列主題：    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/verify-connectivity.html)
+ 設定任務子網路的傳出規則，允許連接埠 443 的 HTTPS 與 DNS (TCP) 流量。如需詳細資訊，請參閱 *Amazon Elastic Compute Cloud User Guide* 中的 [Configure security group rules](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/changing-security-group.html#add-remove-security-group-rules)。
+ 若使用自訂網域名稱伺服器，請確認 DNS 查詢的設定。查詢必須具有連接埠 53 的傳出存取權，並使用 UDP 與 TCP 通訊協定。此外，其必須具備連接埠 443 的 HTTPS 存取權。如需詳細資訊，請參閱 *Amazon Elastic Compute Cloud User Guide* 中的 [Configure security group rules](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/changing-security-group.html#add-remove-security-group-rules)。
+ 如果子網路具有網路 ACL，則需要如下 ACL 規則：
  + 傳出規則，允許連接埠 1024-65535 的流量。
  + 傳入規則，允許連接埠 443 的 TCP 流量。

  如需有關如何設定規則的資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Control traffic to subnets using network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。

## 修正網路問題
<a name="fix-network-issues"></a>

當 `AWSSupport-TroubleshootECSTaskFailedToStart` 執行手冊結果顯示存在網路問題時，請檢查下列組態：

### 在公有子網路中使用 awsvpc 網路模式的任務
<a name="fix-network-issues-fargate-public"></a>

根據執行手冊執行下列組態：
+ 針對公有子網路中的任務，您必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **ENABLED** (啟用)。如需詳細資訊，請參閱[將應用程式作為 Amazon ECS 任務執行](standalone-task-create.md)。
+ 您需要閘道來處理網際網路流量。任務子網路的路由表需要有通往閘道的流量路由。

  如需詳細資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Add and remove routes from a route table](https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html#AddRemoveRoutes)。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/verify-connectivity.html)
+ 如果任務子網路具有網路 ACL，則需要如下 ACL 規則：
  + 傳出規則，允許連接埠 1024-65535 的流量。
  + 傳入規則，允許連接埠 443 的 TCP 流量。

  如需有關如何設定規則的資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Control traffic to subnets using network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。

### 在私有子網路中使用 awsvpc 網路模式的任務
<a name="fix-network-issues-fargate-private"></a>

根據執行手冊執行下列組態：
+ 啟動任務時，在**自動指派公有 IP** 欄位中選擇**停用**。
+  在 VPC 中設定 NAT 閘道，將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [NAT Gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。
+ 任務子網路的路由表需要有通往 NAT 閘道的流量路由。

  如需詳細資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Add and remove routes from a route table](https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html#AddRemoveRoutes)。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/verify-connectivity.html)
+ 如果任務子網路具有網路 ACL，則需要如下 ACL 規則：
  + 傳出規則，允許連接埠 1024-65535 的流量。
  + 傳入規則，允許連接埠 443 的 TCP 流量。

  如需有關如何設定規則的資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Control traffic to subnets using network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。

### 在公有子網路中不使用 awsvpc 網路模式的任務
<a name="fix-network-issues-ec2-public"></a>

根據執行手冊執行下列組態：
+ 當您建立叢集時，請在 **Amazon EC2 執行個體聯網**區段的**自動指派 IP** 欄位中選擇**啟用**。

  此選項會將公有 IP 位址指派給執行個體主要網路介面。
+ 您需要閘道來處理網際網路流量。執行個體子網路的路由表需要有通往閘道的流量路由。

  如需詳細資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Add and remove routes from a route table](https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html#AddRemoveRoutes)。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/verify-connectivity.html)
+ 如果執行個體子網路具有網路 ACL，則需要如下 ACL 規則：
  + 傳出規則，允許連接埠 1024-65535 的流量。
  + 傳入規則，允許連接埠 443 的 TCP 流量。

  如需有關如何設定規則的資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Control traffic to subnets using network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。

### 在私有子網路中不使用 awsvpc 網路模式的任務
<a name="fix-network-issues-fargate-private"></a>

根據執行手冊執行下列組態：
+ 當您建立叢集時，請在 **Amazon EC2 執行個體聯網**區段的**自動指派 IP** 欄位中選擇**停用**。
+  在 VPC 中設定 NAT 閘道，將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [NAT 閘道](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。
+ 執行個體子網路的路由表需要有通往 NAT 閘道流量的路由。

  如需詳細資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Add and remove routes from a route table](https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html#AddRemoveRoutes)。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonECS/latest/developerguide/verify-connectivity.html)
+ 如果任務子網路具有網路 ACL，則需要如下 ACL 規則：
  + 傳出規則，允許連接埠 1024-65535 的流量。
  + 傳入規則，允許連接埠 443 的 TCP 流量。

  如需有關如何設定規則的資訊，請參閱 *Amazon Virtual Private Cloud User Guide* 中的 [Control traffic to subnets using network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。