

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](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 ]

**适用于 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 参考 (V* 4) [DeleteCluster](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 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 参考 (V* 5) [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 的详细信息，请参阅适用[DeleteCluster](https://docs.rs/aws-sdk-ecs/latest/aws_sdk_ecs/client/struct.Client.html#method.delete_cluster)于 *Rust 的AWS SDK API 参考*。

------