module "api_logs" {
source = "registry.patterneddesigns.ca/essentials/cloudwatch-logs/aws"
version = "1.3.0"
log_group_name = "/app/api"
retention_in_days = 30
metric_filters = [
{
name = "error-count"
pattern = "ERROR"
metric_name = "ErrorCount"
metric_namespace = "MyApp/API"
},
{
name = "warning-count"
pattern = "WARN"
metric_name = "WarningCount"
metric_namespace = "MyApp/API"
},
{
name = "status-500"
pattern = "[ip, id, user, timestamp, request, status=5*, size]"
metric_name = "5xxErrors"
metric_namespace = "MyApp/API"
}
]
}
# Create alarms based on metrics
resource "aws_cloudwatch_metric_alarm" "high_errors" {
alarm_name = "api-high-error-rate"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
metric_name = "ErrorCount"
namespace = "MyApp/API"
period = 300
statistic = "Sum"
threshold = 10
alarm_description = "Error count exceeded threshold"
alarm_actions = [aws_sns_topic.alerts.arn]
}