Custom Cloudwatch Dashboard to Monitor Lambdas
Using AWS CDK
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.
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:
Then you have to create your own dashboard using either,
- AWS Console (manually)
- AWS Cloud Formation (declaratively)
- Terraform (declarative)
- 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
mkdir monitoring
cd monitoring
cdk init monitoring --language typescript
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
npm run build && cdk deploy MonitoringStack --profile yourprofile
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 !!!