How to get an alert if an AWS lambda does not get invoked during the last 24 hours

This article is a part of my "100 data engineering tutorials in 100 days" challenge. (66/100)

When an AWS Lambda runs when some external client accesses a REST endpoint or sends a message to a queue, it may be difficult to notice that something outside of our infrastructure no longer works, and the Lambda is not invoked anymore.

I prefer to get a notification when something externally invoked is no longer used. After all, this usually indicates problems upstream, and it is good to solve them before the users of my data notice the issue.

To get notified when an AWS Lambda is not invoked for too long, we can setup a CloudWatch alert using Terraform.

In this example, I track the invocations of my_lambda_handler, and I want to get a notification if it was not used for over one hour:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
resource "aws_cloudwatch_metric_alarm" "my_lambda_handler_alert" {
  alarm_name = "my_lambda_handler_alert"
  comparison_operator = "LessThanThreshold"
  evaluation_periods = 1
  period = 3600
  threshold = 1
  metric_name = "Invocations"
  namespace = "AWS/Lambda"
  statistic = "Maximum"
  alarm_description = "Triggers an alert if my_lambda_handler is not used for over one hour."
  alarm_actions             = [the_alert_action]
  ok_actions                = [the_ok_action]
  insufficient_data_actions = [the_no_data_action]
  dimensions = {
    FunctionName = "my_lambda_handler"
  }
} 

Subscribe to the newsletter and join the free email course.


Remember to share on social media!
If you like this text, please share it on Facebook/Twitter/LinkedIn/Reddit or other social media.

If you want to contact me, send me a message on LinkedIn or Twitter.

Would you like to have a call and talk? Please schedule a meeting using this link.


Bartosz Mikulski
Bartosz Mikulski * MLOps Engineer / data engineer * conference speaker * co-founder of Software Craft Poznan & Poznan Scala User Group

Subscribe to the newsletter and get access to my free email course on building trustworthy data pipelines.