Skip to content

Commit a4887bf

Browse files
committed
Finaliza infraestrutura
1 parent f5fa931 commit a4887bf

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

terraform/cloudwatch/cloudwatch.tf

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
variable "sns_arn" {
2+
type = string
3+
}
4+
5+
resource "aws_cloudwatch_log_metric_filter" "lambda_log_filter" {
6+
name = "lambda-log-filter"
7+
pattern = "{ $.eventType = Error }" # Substitua pelo padrão que você deseja monitorar
8+
log_group_name = "/aws/lambda/events" # Substitua pelo nome do grupo de log correto
9+
10+
metric_transformation {
11+
name = "ErrorCount"
12+
namespace = "Custom/CloudWatchLogs"
13+
value = "1"
14+
default_value = "0"
15+
}
16+
}
17+
18+
resource "aws_cloudwatch_metric_alarm" "lambda_log_alarm" {
19+
alarm_name = "lambda-log-alarm"
20+
alarm_description = "Alarm triggered on CloudWatch Logs"
21+
comparison_operator = "GreaterThanOrEqualToThreshold"
22+
evaluation_periods = "1"
23+
metric_name = "ErrorCount"
24+
namespace = "Custom/CloudWatchLogs"
25+
period = "60"
26+
statistic = "SampleCount"
27+
threshold = "1"
28+
alarm_actions = [var.sns_arn]
29+
#alarm_description = "Lambda Log Error Alarm"
30+
#alarm_name = "Lambda Log Error Alarm"
31+
treat_missing_data = "missing"
32+
}
33+
34+
resource "aws_cloudwatch_log_metric_filter" "lambda_log_filter_subscription" {
35+
name = "lambda-log-filter-subscription"
36+
pattern = "{ $.eventType = Error }" # Substitua pelo padrão que você deseja monitorar
37+
log_group_name = "/aws/lambda/events" # Substitua pelo nome do grupo de log correto
38+
39+
metric_transformation {
40+
name = "ErrorCountSubscription"
41+
namespace = "Custom/CloudWatchLogs"
42+
value = "1"
43+
}
44+
}

terraform/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ module "website" {
2626

2727
module "sns" {
2828
source = "./sns"
29+
}
30+
31+
output "sns_arn" {
32+
value = module.sns.sns_arn
33+
}
34+
35+
module "cloudwatch" {
36+
source = "./cloudwatch"
37+
sns_arn = module.sns.sns_arn
2938
}

terraform/sns/sns.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
provider "aws" {
2-
region = "us-east-1" # Substitua pela região desejada
3-
}
4-
51
resource "aws_sns_topic" "example_topic" {
62
name = "example-topic"
73
}
84

95
variable "email_subscription" {
106
type = string
11-
default = "niveaabreu@al.insper.edu.br" # Insira o endereço de e-mail para sobregravação aqui
7+
default = "niveaadl@al.insper.edu.br" # Insira o endereço de e-mail para sobregravação aqui
128
}
139

1410
resource "aws_sns_topic_subscription" "email_subscription" {
1511
topic_arn = aws_sns_topic.example_topic.arn
1612
protocol = "email"
1713
endpoint = var.email_subscription
1814
}
15+
16+
output "sns_arn" {
17+
value = aws_sns_topic.example_topic.arn
18+
}

0 commit comments

Comments
 (0)