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"
  }
} 

Did you enjoy reading this article?
Would you like to learn more about software craft in data engineering and MLOps?

Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!

Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.

Bartosz Mikulski

Bartosz Mikulski

  • Data/MLOps engineer by day
  • DevRel/copywriter by night
  • Python and data engineering trainer
  • Conference speaker
  • Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
  • Twitter: @mikulskibartosz
Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.