Skip to content

Commit

Permalink
feat(cloudwatch): dashboard variables (aws#26285)
Browse files Browse the repository at this point in the history
This change add the support for dashboard variables in CDK https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_dashboard_variables.html. It allows to reduce the number of repeated  CloudWatch dashboards by unifying them into one managed with variables.


Closes aws#26200

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Stacy-D authored and bmoffatt committed Jul 28, 2023
1 parent 0790b3f commit 56ff8d7
Show file tree
Hide file tree
Showing 14 changed files with 1,031 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "32.0.0",
"files": {
"b633bcb492f09d5f22533ce8a0e06c6db179f3774bf3675afc4df8b1dccaa645": {
"source": {
"path": "DashboardVariablesIntegrationTest.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "b633bcb492f09d5f22533ce8a0e06c6db179f3774bf3675afc4df8b1dccaa645.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"Resources": {
"DashCCD7F836": {
"Type": "AWS::CloudWatch::Dashboard",
"Properties": {
"DashboardBody": {
"Fn::Join": [
"",
[
"{\"widgets\":[{\"type\":\"text\",\"width\":6,\"height\":2,\"x\":0,\"y\":0,\"properties\":{\"markdown\":\"The dashboard is showing RegionPlaceholder region\",\"background\":\"transparent\"}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":2,\"properties\":{\"view\":\"timeSeries\",\"title\":\"My fancy graph\",\"region\":\"",
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[\"AWS/S3\",\"BucketSizeBytes\",\"BucketName\",\"my-bucket\",\"StorageType\",\"StandardStorage\",{\"label\":\"[BucketName: ${PROP('Dim.BucketName')}] BucketSizeBytes\",\"stat\":\"Maximum\"}]],\"yAxis\":{}}}],\"variables\":[{\"pattern\":\"RegionPlaceholder\",\"type\":\"pattern\",\"inputType\":\"radio\",\"id\":\"region3\",\"defaultValue\":\"us-east-1\",\"visible\":true,\"label\":\"RegionPatternWithValues\",\"values\":[{\"label\":\"IAD\",\"value\":\"us-east-1\"},{\"label\":\"DUB\",\"value\":\"us-west-2\"}]},{\"property\":\"BucketName\",\"type\":\"property\",\"inputType\":\"select\",\"id\":\"BucketName\",\"defaultValue\":\"__FIRST\",\"visible\":true,\"label\":\"BucketName\",\"search\":\"{AWS/S3,BucketName,StorageType} MetricName=\\\"BucketSizeBytes\\\"\",\"populateFrom\":\"BucketName\"}]}"
]
]
}
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "32.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "32.0.0",
"testCases": {
"cdk-integ-dashboard-with-variables/DefaultTest": {
"stacks": [
"DashboardVariablesIntegrationTest"
],
"assertionStack": "cdk-integ-dashboard-with-variables/DefaultTest/DeployAssert",
"assertionStackName": "cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"version": "32.0.0",
"artifacts": {
"DashboardVariablesIntegrationTest.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "DashboardVariablesIntegrationTest.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"DashboardVariablesIntegrationTest": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "DashboardVariablesIntegrationTest.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b633bcb492f09d5f22533ce8a0e06c6db179f3774bf3675afc4df8b1dccaa645.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"DashboardVariablesIntegrationTest.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"DashboardVariablesIntegrationTest.assets"
],
"metadata": {
"/DashboardVariablesIntegrationTest/Dash/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "DashCCD7F836"
}
],
"/DashboardVariablesIntegrationTest/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/DashboardVariablesIntegrationTest/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "DashboardVariablesIntegrationTest"
},
"cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"cdkintegdashboardwithvariablesDefaultTestDeployAssertE08F481E.assets"
],
"metadata": {
"/cdk-integ-dashboard-with-variables/DefaultTest/DeployAssert/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/cdk-integ-dashboard-with-variables/DefaultTest/DeployAssert/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "cdk-integ-dashboard-with-variables/DefaultTest/DeployAssert"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading

0 comments on commit 56ff8d7

Please sign in to comment.