Track your Lambda or other AWS Resources near-realtime with cloudwatch metrics using AWS CDK as Infrastructure as Code

The goal here is to track your cost for a Lambda function in near-realtime its have avg. 10min delay and it's better than the normal budget limit trigger there are around 24 hours behind, which means you can track resources there going crazy before your get a huge bill.

So what we gonna touch on in this article will be Lambda, Event Bridge Trigger, and CloudWatch Metric data.

Lambda function to track execution costs and monitor infrastructure

First, we need the basic stack where we are creating 2 Lambda functions, one for test reason there contain a 5-sec sleep function to collect some data for us, and one there do our Lambda cost calculation and send it back to our CloudWatch Metric so we can see it inside CloudWatch Metric explore.

Then we are adding an event scheduler to trigger our cost monitor calculator every 5 min using EventBridge.

--

--

Paris Nakita Kejser
DevOps Engineer, Software Architect and Software Developering

DevOps Engineer, Software Architect, Software Developer, Data Scientist and identify me as a non-binary person.