【问题标题】:Cloudwatch Dashboard error in CloudformationCloudformation 中的 Cloudwatch 仪表板错误
【发布时间】:2021-07-07 15:49:38
【问题描述】:

我正在尝试使用 cloudformation 中的 JSON 在 AWS 系统管理器中创建 cloudwatch 仪表板。我有一个模板,其中堆栈中已经运行了几个 lambda 函数。我更新如下:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "The AWS CloudFormation template for deployment. Version 1.0",
"Mappings": {
  "SourceCode": {
    "General": {
      "S3Bucket": "solutions",
      "KeyPrefix": "connected-solution/latest"
    }
  }
},
"Resources": {
  "dashboard": {
    "Type": "AWS::CloudWatch::Dashboard",
    "Properties": {
      "DashboardName": "Dynamodb-LambdaDashboard-xxx",
      "DashboardBody": {
        "widgets": [
          {
            "type": "metric",
            "x": 0,
            "y": 0,
            "width": 12,
            "height": 7,
            "properties": {
              "metrics": [
                [
                  "AWS/DynamoDB",
                  "UserErrors"
                ]
              ],
              "view": "timeSeries",
              "stacked": false,
              "period": 300,
              "stat": "Sum",
              "region": "us-east-1"
            }
          }
        ]
      }
    }
  }
}

}

当我尝试更新堆栈时出现以下错误:

Property validation failure: [Value of property {/DashboardBody} does not match type {String}]

请指教。让我知道如果有任何问题, 谢谢,

【问题讨论】:

    标签: json amazon-web-services amazon-cloudformation amazon-cloudwatch dashboard


    【解决方案1】:

    DashboardBody 应该是 string,而不是 json 对象。您必须 stringify(将 json 对象转换为字符串)您的 DashboardBody。例如:

    {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "The AWS CloudFormation template for deployment. Version 1.0",
    "Mappings": {
      "SourceCode": {
        "General": {
          "S3Bucket": "solutions",
          "KeyPrefix": "connected-solution/latest"
        }
      }
    },
    "Resources": {
      "dashboard": {
        "Type": "AWS::CloudWatch::Dashboard",
        "Properties": {
          "DashboardName": "Dynamodb-LambdaDashboard-xxx",
          "DashboardBody": "{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":7,\"properties\":{\"metrics\":[[\"AWS/DynamoDB\",\"UserErrors\"]],\"view\":\"timeSeries\",\"stacked\":false,\"period\":300,\"stat\":\"Sum\",\"region\":\"us-east-1\"}}]}"
        }
      }
    }
    

    【讨论】:

    • 您能详细说明一下吗?我不知道该怎么做。
    • @AliBokhari 我更新了答案。基本上你的 json 必须是字符串。看看我的回答,但请注意,可能需要进一步调整,因为从您的问题中不清楚DashboardBody 的结束位置。它很难阅读。
    • 完美,谢谢@Marcin。我现在了解字符串结构了!
    • @AliBokhari 没问题。很高兴它奏效了。如果答案有帮助,我们将不胜感激。
    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2020-06-23
    • 2019-10-30
    • 1970-01-01
    • 2019-03-30
    • 2019-11-11
    相关资源
    最近更新 更多