ryantuck
ryantuck

Reputation: 6684

How to monitor for lack of Lambda invocation in AWS Cloudwatch

We've ran into issues where lambdas don't end up running when we expect them to, whether triggered from a Cloudwatch Rule or some other source. I'd like to configure a Cloudwatch Alarm to alert me if a lambda doesn't run in an expected time period.

My first pass was to create the following alarm (for a lambda I expect to run once per day):

sum(invocations) < 1 for time period of 1 day

The problem with this is that if the lambda never gets invoked, it never generates a data point in Cloudwatch Metrics, and consequently the alarm stays in an insufficient data state.

I'm thinking I could write a separate lambda that would use boto3 to find the timestamp on the most recent logstream for the lambda in question and use some logic to determine if it's running properly or not - but this seems like a ridiculous solution.

Is there a way to implement this properly in Cloudwatch Alarms?

Upvotes: 4

Views: 2228

Answers (2)

kuldeep mishra
kuldeep mishra

Reputation: 154

The problem is sum registers 0 as no data points. thus alarm goes to "Insufficient Data" state rather than "In Alarm" state. As a work around, you can do the following:

1. goto "Missing data treatment" section inside Alarm, then choose: 2. "Treat missing data as bad(breaching thresold)"

This should set the state in Alarm state, when you have 0 invocation within 24hrs.

Upvotes: 2

d-mcc-af
d-mcc-af

Reputation: 71

Having spent around half a day looking to solve the same problem, I've come to the conclusion that it's not possible to solve this using only CloudWatch. We've had to make do with an INSUFFICIENT_DATA state to highlight a lack of invocation.

Upvotes: 0

Related Questions