-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(logwriter): subscribe on log group creation (#172)
This commit adds an eventbridge rule to trigger the subscriber lambda on log group creation. This functionality was missing from terraform, but correctly implemented in cloudformation.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
resource "aws_cloudwatch_event_rule" "discovery" { | ||
count = local.has_discovery_rate ? 1 : 0 | ||
name_prefix = local.name_prefix | ||
description = "Subscribe new log groups. Requires CloudTrail in target region." | ||
state = "ENABLED" | ||
|
||
event_pattern = <<-EOF | ||
{ | ||
"source": ["aws.logs"], | ||
"detail-type": ["AWS API Call via CloudTrail"], | ||
"detail": { | ||
"eventSource": ["logs.amazonaws.com"], | ||
"eventName": ["CreateLogGroup"] | ||
} | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "discovery" { | ||
count = local.has_discovery_rate ? 1 : 0 | ||
rule = aws_cloudwatch_event_rule.discovery[0].name | ||
arn = aws_sqs_queue.queue.arn | ||
|
||
input_transformer { | ||
input_paths = { | ||
logGroupName = "$.detail.requestParameters.logGroupName" | ||
} | ||
|
||
input_template = jsonencode({ | ||
"subscribe" : { | ||
"logGroups" : [ | ||
{ | ||
"logGroupName" : "<logGroupName>" | ||
} | ||
] | ||
} | ||
}) | ||
} | ||
} |