log_group_name

Type string
Module cloudwatch-logs
Version 1.0.0

Name of the CloudWatch Log Group. Use this for referencing the log group in other resources and for CloudWatch Logs Insights queries.

The name of the CloudWatch Log Group. Use this for referencing the log group in other resources and for CloudWatch Logs Insights queries.

Example Value

/aws/lambda/my-function

Common Use Cases

Lambda Function Configuration

module "my_function" {
  source = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"

  function_name = "my-function"
  # ... other config

  environment_variables = {
    LOG_GROUP = module.app_logs.log_group_name
  }
}

CloudWatch Logs Insights Query

resource "aws_cloudwatch_query_definition" "errors" {
  name = "errors-last-hour"

  log_group_names = [
    module.app_logs.log_group_name
  ]

  query_string = <<-EOT
    fields @timestamp, @message
    | filter @message like /ERROR/
    | sort @timestamp desc
    | limit 100
  EOT
}

Metric Filter Reference

resource "aws_cloudwatch_log_metric_filter" "custom" {
  name           = "custom-metric"
  log_group_name = module.app_logs.log_group_name
  pattern        = "{ $.level = \"ERROR\" }"

  metric_transformation {
    name      = "CustomErrorCount"
    namespace = "MyApp"
    value     = "1"
  }
}

Usage

module "cloudwatch_logs" {
  source  = "registry.patterneddesigns.ca/essentials/cloudwatch-logs/aws"
  version = "1.0.0"
  # ... inputs
}

# Access this output
output "log_group_name" {
  value = module.cloudwatch_logs.log_group_name
}