---
title: "How to get an alert if an AWS lambda does not get invoked during the last 24 hours"
description: "How to get a notification when AWS Lambda stops begin used"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/alert-when-aws-lambda-does-not-get-invoked
---

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:

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

