I am trying to create cloudwatch dashboards in AWS system manager using JSON in cloudformation. I have a template in which there are a couple of lambda functions already running in the stack. I updated it as follows:
{
"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"
}
}
]
}
}
}
}
}
I am getting the following error when I try to update the stack:
Property validation failure: [Value of property {/DashboardBody} does not match type {String}]
Please advise. Let me know if there are any questions, Thank you,
DashboardBody
should be string
, not json object. You have to stringify (convert json object to string) your DashboardBody
. For example:
{
"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\"}}]}"
}
}
}