Skip to content

Instantly share code, notes, and snippets.

@ashutoshkarna03
Created March 18, 2023 23:29
Show Gist options
  • Save ashutoshkarna03/904e8a755b50fc2d2af1613677d18e6a to your computer and use it in GitHub Desktop.
Save ashutoshkarna03/904e8a755b50fc2d2af1613677d18e6a to your computer and use it in GitHub Desktop.
# metric creation for the cloudwatch logs
resource "aws_cloudwatch_log_metric_filter" "cloudwatch_filter" {
name = "MyLogFilter"
log_group_name = "/aws/ecs/my-service"
pattern = "This text should trigger alarm"
metric_transformation {
name = "MyLogMetric"
namespace = "MyLogNamespace"
value = "1"
}
}
# cloudwatch alarm for the metric
resource "aws_cloudwatch_metric_alarm" "cloudwatch_logs_alarm" {
alarm_name = "MyLogBasedAlarm"
alarm_description = "Alarm triggered by Cloudwatch Log ..."
alarm_actions = var.alarm_actions
treat_missing_data = "missing"
metric_name = lookup(aws_cloudwatch_log_metric_filter.cloudwatch_filter.metric_transformation[0], "name")
threshold = "10"
statistic = "Sum"
comparison_operator = "GreaterThanThreshold"
datapoints_to_alarm = "1"
evaluation_periods = "1"
period = "300"
namespace = lookup(aws_cloudwatch_log_metric_filter.cloudwatch_filter.metric_transformation[0], "namespace")
tags = var.tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment