You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法向AWS CloudWatch Dashboard添加Widget的技术求助

CloudWatch Dashboard添加Widget保存失败的报错排查

操作流程

  • 在Amazon Kinesis/Analytics应用中,点击目标图表的「View in metrics」
  • 在跳转页面点击「Actions/Add to dashboard」,选择目标仪表盘后完成添加,预览可正常显示图表,但点击「Save」时触发以下报错:
There was an error while trying to save your dashboard:
The dashboard body is invalid, there are 6 validation errors: [ 
{ "dataPath": "/widgets/5/properties/metrics/0", "message": "Should NOT have more than 4 items" }, 
{ "dataPath": "/widgets/5/properties/metrics/1", "message": "Should NOT have more than 4 items" },
{ "dataPath": "/widgets/5/properties/yAxis/left", "message": "Should be null" },
{ "dataPath": "/widgets/5/properties/yAxis/left", "message": "Should match some schema in anyOf" }, 
{ "dataPath": "/widgets/5/properties/yAxis/right", "message": "Should be null" }, 
{ "dataPath": "/widgets/5/properties/yAxis/right", "message": "Should match some schema in anyOf" } ]

现状说明

  • 未手动输入任何代码,仅通过AWS控制台菜单操作
  • 当前仪表盘包含4个日志组件+1个图表,本次添加的是第6个组件

现有仪表盘源码(敏感信息已遮挡)

{
    "widgets": [
        {
            "height": 6,
            "width": 24,
            "y": 12,
            "x": 0,
            "type": "log",
            "properties": {
                "query": "SOURCE '/aws/kinesis-analytics/.......' | fields @timestamp, message | filter applicationARN like /arn:aws:kinesisanalytics:eu-west-1:......./| filter messageType = \"ERROR\"| sort @timestamp desc",
                "region": "eu-west-1",
                "title": "Error log (last 1000 records)",
                "view": "table"
            }
        },
        {
            "height": 6,
            "width": 24,
            "y": 6,
            "x": 0,
            "type": "log",
            "properties": {
                "query": "SOURCE '/aws/kinesis-analytics/.......' | fields @timestamp, message | filter applicationARN like /arn:aws:kinesisanalytics:eu-west-1:......./|  sort @timestamp desc",
                "region": "eu-west-1",
                "title": "Full log (last 1000 records)",
                "view": "table"
            }
        },
        {
            "height": 6,
            "width": 24,
            "y": 18,
            "x": 0,
            "type": "log",
            "properties": {
                "query": "SOURCE '/aws/kinesis-analytics/.......' | fields @timestamp, message | filter applicationARN like /arn:aws:kinesisanalytics:eu-west-1:......./| filter message like / OEE Data Streaming app v / | sort @timestamp desc",
                "region": "eu-west-1",
                "title": "Version - works only right after deployment, othervise look at the name of the jar file :) ",
                "view": "table"
            }
        },
        {
            "height": 6,
            "width": 24,
            "y": 0,
            "x": 0,
            "type": "log",
            "properties": {
                "query": "SOURCE '/aws/kinesis-analytics/.......' | fields @timestamp, message | filter applicationARN like /arn:aws:kinesisanalytics:eu-west-1:338785721659:.......") | sort @timestamp desc",
                "region": "eu-west-1",
                "stacked": false,
                "title": "OEE app inside logs",
                "view": "table"
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 24,
            "x": 0,
            "type": "metric",
            "properties": {
                "region": "eu-west-1",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                },
                "metrics": [
                    [ "AWS/Kinesis", "GetRecords.Records", "StreamName", ".......", { "id": "m3", "visible": true } ]
                ],
                "stat": "Sum",
                "title": "GetRecords - .......",
                "start": "-PT3H",
                "end": "P0D",
                "view": "timeSeries",
                "stacked": false
            }
        }
    ]
}

尝试添加的Uptime Widget源码

{
            "type": "metric",
            "x": 6,
            "y": 24,
            "width": 6,
            "height": 6,
            "properties": {
                "region": "eu-west-1",
                "yAxis": {
                    "left": {
                        "min": 0,
                        "stat": "Maximum",
                        "showUnits": false
                    },
                    "right": {
                        "min": 0,
                        "stat": "Maximum",
                        "showUnits": false
                    }
                },
                "metrics": [
                    [ "AWS/KinesisAnalytics", "uptime", "Application", "...", { "yAxis": "left", "label": "uptime", "stat": "Maximum", "showUnits": false } ],
                    [ ".", "fullRestarts", ".", ".", { "yAxis": "right", "label": "fullRestarts", "stat": "Maximum", "showUnits": false } ]
                ],
                "stat": "Maximum",
                "title": "Uptime (Milliseconds) - Maximum",
                "start": "-PT3H",
                "end": "P0D",
                "view": "timeSeries",
                "stacked": false
            }
        }

报错原因及修复方案

1. Metrics数组格式不符合校验规则

报错提示每个metrics条目不能超过4项,问题出在第二个metric条目的简写写法(使用.复用命名空间和维度),这种简写不被CloudWatch Dashboard的JSON schema支持。

修复方式:将简写的.替换为实际的命名空间和维度值,示例:

// 原写法
[ ".", "fullRestarts", ".", ".", { "yAxis": "right", "label": "fullRestarts", "stat": "Maximum", "showUnits": false } ]

// 修改后
[ "AWS/KinesisAnalytics", "fullRestarts", "Application", "...", { "yAxis": "right", "label": "fullRestarts", "stat": "Maximum", "showUnits": false } ]

2. Y轴配置包含非法属性

报错提示yAxis的left/right字段不符合schema,原因是yAxis配置中包含了stat和showUnits属性——这两个属性应该放在widget顶级配置或单个metric的配置中,不属于yAxis的合法配置项。

修复方式:移除yAxis.left和yAxis.right中的stat、showUnits属性,仅保留合法的min属性:

// 原写法
"yAxis": {
    "left": {
        "min": 0,
        "stat": "Maximum",
        "showUnits": false
    },
    "right": {
        "min": 0,
        "stat": "Maximum",
        "showUnits": false
    }
}

// 修改后
"yAxis": {
    "left": {
        "min": 0
    },
    "right": {
        "min": 0
    }
}

修复后的完整Uptime Widget代码

{
    "type": "metric",
    "x": 6,
    "y": 24,
    "width": 6,
    "height": 6,
    "properties": {
        "region": "eu-west-1",
        "yAxis": {
            "left": {
                "min": 0
            },
            "right": {
                "min": 0
            }
        },
        "metrics": [
            [ "AWS/KinesisAnalytics", "uptime", "Application", "...", { "yAxis": "left", "label": "uptime", "stat": "Maximum", "showUnits": false } ],
            [ "AWS/KinesisAnalytics", "fullRestarts", "Application", "...", { "yAxis": "right", "label": "fullRestarts", "stat": "Maximum", "showUnits": false } ]
        ],
        "stat": "Maximum",
        "title": "Uptime (Milliseconds) - Maximum",
        "start": "-PT3H",
        "end": "P0D",
        "view": "timeSeries",
        "stacked": false
    }
}

内容的提问来源于stack exchange,提问作者ForestG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 09:20:24