将 ListDashboards 与 Amazon SDK 或 CLI 配合使用 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

ListDashboards 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 ListDashboards

.NET
Amazon SDK for .NET
注意

在 GitHub 上查看更多内容。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/// <summary> /// Get a list of dashboards. /// </summary> /// <returns>A list of DashboardEntry objects.</returns> public async Task<List<DashboardEntry>> ListDashboards() { var results = new List<DashboardEntry>(); var paginateDashboards = _amazonCloudWatch.Paginators.ListDashboards( new ListDashboardsRequest()); // Get the entire list using the paginator. await foreach (var data in paginateDashboards.DashboardEntries) { results.Add(data); } return results; }
  • 有关 API 详细信息,请参阅《Amazon SDK for .NET API 参考》中的 ListDashboards

Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void listDashboards(CloudWatchClient cw) { try { ListDashboardsIterable listRes = cw.listDashboardsPaginator(); listRes.stream() .flatMap(r -> r.dashboardEntries().stream()) .forEach(entry -> { System.out.println("Dashboard name is: " + entry.dashboardName()); System.out.println("Dashboard ARN is: " + entry.dashboardArn()); }); } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 ListDashboards

Kotlin
适用于 Kotlin 的 SDK
注意

在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

suspend fun listDashboards() { CloudWatchClient { region = "us-east-1" }.use { cwClient -> cwClient .listDashboardsPaginated({}) .transform { it.dashboardEntries?.forEach { obj -> emit(obj) } } .collect { obj -> println("Name is ${obj.dashboardName}") println("Dashboard ARN is ${obj.dashboardArn}") } } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Kotlin API 参考》中的 ListDashboards

PowerShell
适用于 PowerShell 的工具

示例 1:返回您账户的控制面板集合。

Get-CWDashboardList

输出:

DashboardArn DashboardName LastModified Size ------------ ------------- ------------ ---- arn:... Dashboard1 7/6/2017 8:14:15 PM 252

示例 2:返回名称以前缀“dev”开头的账户的控制面板集合。

Get-CWDashboardList -DashboardNamePrefix dev
  • 有关 API 详细信息,请参阅《Amazon Tools for PowerShell Cmdlet 参考》中的 ListDashboards

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将 CloudWatch 与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。