

# 将 `DeleteDashboards` 与 AWS SDK 或 CLI 配合使用
<a name="example_cloudwatch_DeleteDashboards_section"></a>

以下代码示例演示如何使用 `DeleteDashboards`。

操作示例是大型程序的代码摘录，必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文：
+  [了解基本功能](example_cloudwatch_GetStartedMetricsDashboardsAlarms_section.md) 
+  [将函数名称作为变量创建 CloudWatch 控制面板](example_cloudwatch_GettingStarted_031_section.md) 
+  [在 CloudWatch 控制面板中使用属性变量监控多个 Lambda 函数](example_iam_GettingStarted_032_section.md) 

------
#### [ .NET ]

**适用于 .NET 的 SDK (v4)**  
 查看 GitHub，了解更多信息。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv4/CloudWatch#code-examples)中查找完整示例，了解如何进行设置和运行。

```
    /// <summary>
    /// Delete a list of CloudWatch dashboards.
    /// </summary>
    /// <param name="dashboardNames">List of dashboard names to delete.</param>
    /// <returns>True if successful.</returns>
    public async Task<bool> DeleteDashboards(List<string> dashboardNames)
    {
        var deleteDashboardsResponse = await _amazonCloudWatch.DeleteDashboardsAsync(
            new DeleteDashboardsRequest()
            {
                DashboardNames = dashboardNames
            });

        return deleteDashboardsResponse.HttpStatusCode == HttpStatusCode.OK;
    }
```
+  有关 API 详细信息，请参阅《适用于 .NET 的 AWS SDK API Reference》**中的 [DeleteDashboards](https://docs.aws.amazon.com/goto/DotNetSDKV4/monitoring-2010-08-01/DeleteDashboards)。

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

**AWS CLI**  
**删除指定的控制面板**  
以下 `delete-dashboards` 示例删除了指定账户中名为 `Dashboard-A` 和 `Dashboard-B` 的两个控制面板。  

```
aws cloudwatch delete-dashboards \
    --dashboard-names {{Dashboard-A}} {{Dashboard-B}}
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》中的[使用 Amazon CloudWatch 控制面板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DeleteDashboards](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudwatch/delete-dashboards.html)。

------
#### [ Java ]

**适用于 Java 的 SDK 2.x**  
 查看 GitHub，了解更多信息。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/cloudwatch#code-examples)中查找完整示例，了解如何进行设置和运行。

```
    /**
     * Deletes the specified dashboard.
     *
     * @param dashboardName the name of the dashboard to be deleted
     * @return a {@link CompletableFuture} representing the asynchronous operation of deleting the dashboard
     * @throws RuntimeException if the dashboard deletion fails
     */
    public CompletableFuture<DeleteDashboardsResponse> deleteDashboardAsync(String dashboardName) {
        DeleteDashboardsRequest dashboardsRequest = DeleteDashboardsRequest.builder()
            .dashboardNames(dashboardName)
            .build();

        return getAsyncClient().deleteDashboards(dashboardsRequest)
            .whenComplete((response, exception) -> {
                if (exception != null) {
                    throw new RuntimeException("Failed to delete the dashboard: " + dashboardName, exception);
                } else {
                    logger.info("{} was successfully deleted.", dashboardName);
                }
            });
    }
```
+  有关 API 详细信息，请参阅《AWS SDK for Java 2.x API Reference》**中的 [DeleteDashboards](https://docs.aws.amazon.com/goto/SdkForJavaV2/monitoring-2010-08-01/DeleteDashboards)。

------
#### [ Kotlin ]

**适用于 Kotlin 的 SDK**  
 查看 GitHub，了解更多信息。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/cloudwatch#code-examples)中查找完整示例，了解如何进行设置和运行。

```
suspend fun deleteDashboard(dashboardName: String) {
    val dashboardsRequest =
        DeleteDashboardsRequest {
            dashboardNames = listOf(dashboardName)
        }
    CloudWatchClient.fromEnvironment { region = "us-east-1" }.use { cwClient ->
        cwClient.deleteDashboards(dashboardsRequest)
        println("$dashboardName was successfully deleted.")
    }
}
```
+  有关 API 详细信息，请参阅《AWS SDK for Kotlin API Reference》**中的 [DeleteDashboards](https://sdk.amazonaws.com/kotlin/api/latest/index.html)。

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

**适用于 PowerShell V4 的工具**  
**示例 1：删除指定的控制面板，继续操作前提示确认。要绕过确认，请在命令中添加 -Force 开关。**  

```
Remove-CWDashboard -DashboardName Dashboard1
```
+  有关 API 详细信息，请参阅《*AWS Tools for PowerShell Cmdlet Reference (V4)*》中的 [DeleteDashboards](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**示例 1：删除指定的控制面板，继续操作前提示确认。要绕过确认，请在命令中添加 -Force 开关。**  

```
Remove-CWDashboard -DashboardName Dashboard1
```
+  有关 API 详细信息，请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》**中的 [DeleteUserPolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

------

有关 AWS SDK 开发人员指南和代码示例的完整列表，请参阅 [将 CloudWatch 与 AWS SDK 结合使用](sdk-general-information-section.md)。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。