Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Delete CloudWatch dashboards using an Amazon SDK
The following code examples show how to delete Amazon CloudWatch dashboards.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- .NET
-
- Amazon SDK for .NET
-
/// <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;
}
- Java
-
- SDK for Java 2.x
-
public static void deleteDashboard(CloudWatchClient cw, String dashboardName) {
try {
DeleteDashboardsRequest dashboardsRequest = DeleteDashboardsRequest.builder()
.dashboardNames(dashboardName)
.build();
cw.deleteDashboards(dashboardsRequest);
System.out.println(dashboardName + " was successfully deleted.");
} catch (CloudWatchException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
- Kotlin
-
- SDK for Kotlin
-
This is prerelease documentation for a feature in preview release. It is subject to change.
suspend fun deleteDashboard(dashboardName: String) {
val dashboardsRequest = DeleteDashboardsRequest {
dashboardNames = listOf(dashboardName)
}
CloudWatchClient { region = "us-east-1" }.use { cwClient ->
cwClient.deleteDashboards(dashboardsRequest)
println("$dashboardName was successfully deleted.")
}
}
For a complete list of Amazon SDK developer guides and code examples, see
Using CloudWatch with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.