CloudTrail is not integrated with CloudWatch Logs

Configure a monitoring path for audit logs.

Description

Send CloudTrail events to a CloudWatch Logs group to search them or use them in alarms.

Potential impact

CloudWatch metric filters and alarms can miss activity if the trail’s events never reach their log group.

Remediation

Set cloudwatch_logs_log_group_arn to the destination log group and cloudwatch_logs_role_arn to a role CloudTrail can assume to write there. Confirm events arrive before configuring metric filters and alarms.

Examples

Create the role and log group before running the task.

Before

yaml
- name: Create CloudTrail
  community.aws.cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    region: us-east-1
    is_multi_region_trail: true
    enable_log_file_validation: true
    kms_key_id: "alias/MyAliasName"

- name: Create CloudTrail2
  community.aws.cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    region: us-east-1
    is_multi_region_trail: true
    enable_log_file_validation: true
    cloudwatch_logs_role_arn: "arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role"
    kms_key_id: "alias/MyAliasName"

After

yaml
- name: Create CloudTrail
  community.aws.cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    region: us-east-1
    is_multi_region_trail: true
    enable_log_file_validation: true
    cloudwatch_logs_role_arn: "arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role"
    cloudwatch_logs_log_group_arn: "arn:aws:logs:us-east-1:123456789012:log-group:CloudTrail/DefaultLogGroup:*"
    kms_key_id: "alias/MyAliasName"

References