

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# `DeleteCluster` 搭配 AWS SDK 或 CLI 使用
<a name="ecs_example_ecs_DeleteCluster_section"></a>

下列程式碼範例示範如何使用 `DeleteCluster`。

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

**AWS CLI**  
**刪除空叢集**  
以下 `delete-cluster` 範例會刪除指定的空叢集。  

```
aws ecs delete-cluster --cluster MyCluster
```
輸出：  

```
{
    "cluster": {
        "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster",
        "status": "INACTIVE",
        "clusterName": "MyCluster",
        "registeredContainerInstancesCount": 0,
        "pendingTasksCount": 0,
        "runningTasksCount": 0,
        "activeServicesCount": 0
        "statistics": [],
        "tags": []
    }
}
```
如需詳細資訊，請參閱《Amazon ECS 開發人員指南》**中的[刪除叢集](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/delete_cluster.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteCluster](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/delete-cluster.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此 Cmdlet 會刪除指定的 ECS 叢集。您必須從此叢集取消註冊所有容器執行個體，才能將其刪除。**  

```
Remove-ECSCluster -Cluster "LAB-ECS"
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-ECSCluster (DeleteCluster)" on target "LAB-ECS".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [DeleteCluster](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此 Cmdlet 會刪除指定的 ECS 叢集。您必須從此叢集取消註冊所有容器執行個體，才能將其刪除。**  

```
Remove-ECSCluster -Cluster "LAB-ECS"
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-ECSCluster (DeleteCluster)" on target "LAB-ECS".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteCluster](https://docs.aws.amazon.com/powershell/v5/reference)。

------
#### [ Rust ]

**適用於 Rust 的 SDK**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/ecs#code-examples)中設定和執行。

```
async fn remove_cluster(
    client: &aws_sdk_ecs::Client,
    name: &str,
) -> Result<(), aws_sdk_ecs::Error> {
    let cluster_deleted = client.delete_cluster().cluster(name).send().await?;
    println!("cluster deleted: {:?}", cluster_deleted);

    Ok(())
}
```
+  如需 API 詳細資訊，請參閱《AWS SDK for Rust API 參考》**中的 [DeleteCluster](https://docs.rs/aws-sdk-ecs/latest/aws_sdk_ecs/client/struct.Client.html#method.delete_cluster)。

------