Custom Cloudwatch Dashboard to Monitor Lambdas

Using AWS CDK

Kasun Dilunika
dtlpub
2 min readFeb 13, 2020

--

AWS shows lots of monitoring details for a single lambda. But if you want to see the summaries of all the lambdas running, closest you can find is the account level summary dashboard in the Lambda section.

Account-level summary dashboard

It is good, but assume that you want to see the number of invocations or the execution time for each lambda in one graph. Something like this:

Custom Lambda Metrics Dashboard

Then you have to create your own dashboard using either,

  1. AWS Console (manually)
  2. AWS Cloud Formation (declaratively)
  3. Terraform (declarative)
  4. AWS CDK (programmatically)

If you pick the first option, after a few minutes, you might get bored with the repetitive effort you have to put when you create more than a single widget. (maybe not :), but I got bored when I am done with my second widget).

So, if you are a person like me, you will definitely, fallback into options 2, 3 or 4. However, to me, there are only two options left since I was never a big fan of cloud formation!!!

After looking at the syntax and amount of code you have to write, I decided to use a programmatic option.

Let’s start developing the custom dashboard as shown in figure 2 using AWS CDK.

Create a CDK Project (TypeScript)

I will proceed assuming you have installed cdk-cli and you have configured aws profile properly. Otherwise please refer to this starter tutorial by AWS.

https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-typescript.html

Create the MonitoringStack

Add the dashboard to the stack

General function for lambda graph widget

Create two widgets (invocation & duration) and add them to the dashboard

Deploy monitoring dashboard stack

If you have followed all the steps above and you have set of lambdas running in your account, you will see a nice dashboard with two widgets as shown in figure two.

Now the hard work is done! If you want more widgets to be added, it is just adding a couple of lines. Lots of repetitive work is cut down !!!

--

--

Kasun Dilunika
dtlpub

Software Architect at Digital Transformation, NZ