Description
CloudTrail can deliver events to CloudWatch Logs alongside its S3 archive.
Potential impact
CloudWatch metric filters and alarms can miss activity if the trail’s events never reach their log group.
Remediation
Set cloud_watch_logs_group_arn to the destination log group and cloud_watch_logs_role_arn to a role CloudTrail can assume to write there. Confirm events arrive before configuring metric filters and alarms.
Examples
Create the referenced log group and role first. Allow time for the first events to arrive.
Before
hcl
resource "aws_cloudtrail" "example" {
name = "tf-trail-foobar"
s3_bucket_name = aws_s3_bucket.foo.id
s3_key_prefix = "prefix"
include_global_service_events = false
}
After
hcl
resource "aws_cloudtrail" "example" {
name = "tf-trail-foobar"
s3_bucket_name = aws_s3_bucket.foo.id
s3_key_prefix = "prefix"
include_global_service_events = false
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.cloudtrail_log_group.arn}:*"
cloud_watch_logs_role_arn = aws_iam_role.cloud_watch_logs_role.arn
}