Creating Cloudwatch Dashboards per Environment with Python

Creating Cloudwatch Dashboards per Environment with Python

Show Me The Code Already

After installing Cloudwatch Agent to the machines you want to monitor, it’s time to create dashboards to view real-time metrics.

There are some ways to create Cloudwatch Dashboards such as creating them manually by selecting widgets from AWS Console, with Cloudformation etc.

I’ve decided to create them with Python because in DevOps literature, there is no such a thing as manually creating something. I also didn’t want to use Cloudformation because I like scripting and we have many applications to monitor in our company, thus, I needed something to iterate over our environments and create dashboards for each of them.

What Does This Code Do?

This particular code takes one parameter from terminal which is the environment you want to create dashboards for. You execute the script by:

After executing the script, dashboards for that specified environment will get created based on the instance count. Since there is a widget count limitation per dashboard, when widget count exceeds 500, other dashboards will get created. If the count is lower than 500, only one will be created.

Let’s get right into the code!

This Post Has 4 Comments

  1. thanks for the code, however, I am still a learner. Could you please help, I tried your code with one of my VM with CW installed, however it doesnot populates dashboard.

    1. Hello Neil,

      Could you please share more details? What is the output of the script? By CW installed, do you mean the agent?

      1. Hi , seems like widgnet gets created but no data is coming into the dashboards. so, basically the dashboards showing no data inside. Please help


        1. Hello ruchira,

          You need to have some data points(metrics) to be shown on your dashboards. For example, MEM_AVAILABLE is a data point which you collect from your EC2 Instances by CloudWatch Agent. You can set them via AWS Console or apply my previous blog post to collect these metrics. Check it out:

          Also check this documentation:

          Hopefully, this helps.

          Have a good day!

Leave a Reply

Close Menu