Create AWS CloudWatch Dashboard With AWS CDK

This short guide demonstrates creation of the AWS CloudWatch dashboard with AWS CDK tool

Friday, October 16, 2020

The creation of the dashboard is fairly straightforward, however, I did not found any demonstration code online. Thus I created one. We start with the definition of the dashboard object.

The above object is the container for your widgets. Now you can start adding the widgets to your dashboard. There are multiple types of widgets, for this demo let us use the graph widgets.

The widget above creates a single graphed line for the Count metric of the AWS API gateway service. The statistic is the sum over a period of 3 hours. The Y-axis for the graphed line will be on the left side of the graph. The width of the widget is set to 24, which means the full width of the screen.

Let us also demonstrate another graph widget with multiple graphed lines.

This time, a graph will contain two lines. One for the average latency of the API Gateway, and second for the maximum one. Both lines will share the left Y-axis.

Once desired widgets are created, we can put them into the dashboard.

Because we added the widgets one by one, they will be rendered beneath each other.

demo image

If we would set the width of widgets to 12 and add them in a single method call, they would be rendered side by side. I think for the basic demo we can wrap it up here. I hope you got the basic idea of how to work with dashboards via CDK and see the below link for further documentation.

Further Information

The CDK documentation can be found at https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Dashboard.html