Cloudformation 中的 Cloudwatch 仪表板错误

Cloudwatch Dashboard error in Cloudformation

我正在尝试在 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}]

请指教。如果有任何问题,请告诉我, 谢谢,

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\"}}]}"
    }
  }
}