AWS powershell commandlet (Write-CWDashboard) 输出消息 'Should match exactly one schema in oneOf'

AWS powershell commandlet (Write-CWDashboard) outputs message 'Should match exactly one schema in oneOf'

我正在尝试使用 AWS powershell commandlet Write-CWDashboard 创建 AWS cloudwatch 仪表板。尽管命令成功,但它生成的输出消息为 'Should match exactly one schema in oneOf'。完整的详细信息如下,

我想了解为什么会生成该消息。

命令:

Write-CWDashboard -DashboardName 'test' -DashboardBody $DashboardBody;

$DashboardBody 值 json 格式:

{ "widgets": [    
    {
        "type": "metric",
        "x": 0,
        "y": 0,
        "width": 10,
        "height": 10,
        "properties": {
            "region": "us-west-2",
            "metrics": [
["AWS/EC2", "CPUUtilization", "InstanceId", "i-04c3216xyz"]
            ],
            "view": "timeSeries",
            "stacked": false,
            "title": "server01 CPU",
            "legend": {
                "position": "right"
            }
        }
    },  
    {
        "type": "metric",
        "x": 0,
        "y": 10,
        "width": 10,
        "height": 10,
        "properties": {
            "region": "us-west-2",
            "metrics": [
["AWS/EBS", "VolumeReadOps", "VolumeId", "vol-0b1ab41abc"],
["AWS/EBS", "VolumeWriteOps", "VolumeId", "vol-0b1ab41abc"]
            ],
            "view": "timeSeries",
            "stacked": false,
            "annotations": {
            },
            "title": "server01 disk01 IOPs",
            "legend": {
                "position": "right"
            }
        }
    }
    ]}

输出:

DataPath                           Message
--------                           -------
/widgets/1/properties/annotations  Should match exactly one schema in oneOf

您从 annotations 属性.

中获得此异常

来自Dashboard Body Structure and Syntax

annotations

To include an alarm or annotation in the widget, specify an annotations array. For more information about the format, see Dashboard Widget Object: Annotation Properties. Use this parameter only for metric widgets.

Type: Object

Required: An alarm annotation is required only when the widget type is metric and metrics is not specified. A horizontal or vertical annotation is not required.

但是,如您所见,由于您提供了指标,因此不需要提供任何注释。

因此,只需删除 JSON 中的注释 属性。

工作代码片段:

$DashboardBody = @"
{
  "widgets": [
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 10,
      "height": 10,
      "properties": {
        "region": "us-west-2",
        "metrics": [
          [
            "AWS/EC2",
            "CPUUtilization",
            "InstanceId",
            "i-04c3216xyz"
          ]
        ],
        "view": "timeSeries",
        "stacked": false,
        "title": "server01 CPU",
        "legend": {
          "position": "right"
        }
      }
    },
    {
      "type": "metric",
      "x": 0,
      "y": 10,
      "width": 10,
      "height": 10,
      "properties": {
        "region": "us-west-2",
        "metrics": [
          [
            "AWS/EBS",
            "VolumeReadOps",
            "VolumeId",
            "vol-0b1ab41abc"
          ],
          [
            "AWS/EBS",
            "VolumeWriteOps",
            "VolumeId",
            "vol-0b1ab41abc"
          ]
        ],
        "view": "timeSeries",
        "stacked": false,
        "title": "server01 disk01 IOPs",
        "legend": {
          "position": "right"
        }
      }
    }
  ]
}
"@


Write-CWDashboard -DashboardName 'test' -DashboardBody $DashboardBody;