I have a Lambda that is triggered to run every week, and I want to have a CloudWatch alarm if it ever does not run for more than 7 consecutive days.
My thinking was Alarm if < 1 invocation for 8 days
but it does not seem to be possible to set it longer than 24 hours:
The alarm evaluation period (number of datapoints times the period of the metric) must be no longer than 24 hours.
Is there another way to ensure execution of Lambdas that are triggered on a period of greater than 24 hours?
You can use a CloudWatch Events rule that matches on alarm evaluation changes and then triggers a Lambda function that parses the alarm event and creates a customized notification.
Maximum evaluation period is 24 hours.
You can get around that by creating a custom metric using CloudWatch PutMetricData API. You can publish the time elapsed since the last execution of your lambda function and then alarm when the value rises above 8 days.
One way of doing this would be to have your lambda function store the timestamp of execution to DynamoDB every time it triggers. Then you can create a new function that will read that timestamp from DynamoDB and publish the difference between it and current time to a custom metric (have that lambda trigger every 1h for example).
Once you have the new custom metric flowing, you can create an alarm that will fire if the value goes above 8 days for one 1h datapoint (this will solve your initial issue). You can also set the Treat missing data as option to bad - breaching threshold (this will alert you if the second lambda function doesn't trigger).
You should also set alarms on CloudWatch Events errors and Lambda errors. This will alert you if something goes wrong with the scheduling or the lambda itself. But the custom metric I mentioned above will also alert you in the case of human error where someone disables or deletes the event or the function by mistake for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With