

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

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

操作示例是大型程序的代码摘录，必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文：
+  [将函数名称作为变量创建 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>
    /// Get information on a dashboard.
    /// </summary>
    /// <param name="dashboardName">The name of the dashboard.</param>
    /// <returns>A JSON object with dashboard information.</returns>
    public async Task<string> GetDashboard(string dashboardName)
    {
        var dashboardResponse = await _amazonCloudWatch.GetDashboardAsync(
            new GetDashboardRequest()
            {
                DashboardName = dashboardName
            });

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

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

**AWS CLI**  
**检索有关控制面板的信息**  
以下 `get-dashboard` 示例显示了有关指定账户中名为 `Dashboard-A` 的控制面板的信息。  

```
aws cloudwatch get-dashboard \
    --dashboard-name {{Dashboard-A}}
```
输出：  

```
{
    "DashboardArn": "arn:aws:cloudwatch::123456789012:dashboard/Dashboard-A",
    "DashboardBody": "{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":6,\"height\":6,\"properties\":{\"view\":\"timeSeries\",\"stacked\":false,\"metrics\":[[\"AWS/EC2\",\"NetworkIn\",\"InstanceId\",\"i-0131f062232ade043\"],[\".\",\"NetworkOut\",\".\",\".\"]],\"region\":\"us-east-1\"}}]}",
    "DashboardName": "Dashboard-A"
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》中的[使用 Amazon CloudWatch 控制面板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [GetDashboard](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudwatch/get-dashboard.html)。

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

**适用于 PowerShell V4 的工具**  
**示例 1：返回指定控制面板的正文 arn。**  

```
Get-CWDashboard -DashboardName Dashboard1
```
**输出**：  

```
DashboardArn                                          DashboardBody
------------                                          -------------
arn:aws:cloudwatch::123456789012:dashboard/Dashboard1 {...
```
+  有关 API 详细信息，请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》**中的 [GetDashboard](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**示例 1：返回指定控制面板的正文 arn。**  

```
Get-CWDashboard -DashboardName Dashboard1
```
**输出**：  

```
DashboardArn                                          DashboardBody
------------                                          -------------
arn:aws:cloudwatch::123456789012:dashboard/Dashboard1 {...
```
+  有关 API 详细信息，请参阅《AWS Tools for PowerShell Cmdlet 参考（V5）》中的 [GetInventory](https://docs.aws.amazon.com/powershell/v5/reference)**。

------

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