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

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:

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"
Older post

How to set Airflow variables while creating a dev environment

How to use command-line to set Airflow variables

Newer post

Making OFFSET LIMIT queries in AWS Athena

How to use OFFSET in AWS Athena queries