For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-aws-cloudtrail-not-integrated-with-cloudwatch.md.
A documentation index is available at /llms.txt.
CloudTrail must be integrated with CloudWatch Logs so events are available for real-time detection, alerting, and centralized log analysis, and so forensic evidence is retained for incident investigation.
For Ansible tasks using the amazon.aws.cloudtrail or cloudtrail modules, the cloudwatch_logs_role_arn and cloudwatch_logs_log_group_arn properties must be defined. cloudwatch_logs_role_arn should be an IAM role ARN that allows CloudTrail to publish to CloudWatch Logs. cloudwatch_logs_log_group_arn should reference the destination Log Group ARN. Tasks missing either property are flagged.
Secure configuration example:
- name:Create CloudTrail with CloudWatch Logs integrationamazon.aws.cloudtrail:name:my-trails3_bucket_name:my-bucketis_multi_region_trail:yescloudwatch_logs_role_arn:arn:aws:iam::123456789012:role/CloudTrail_CloudWatch_Logs_Rolecloudwatch_logs_log_group_arn:arn:aws:logs:us-east-1:123456789012:log-group:/aws/cloudtrail
Compliant Code Examples
- name:create multi-region trail with validation and tags negativeamazon.aws.cloudtrail:state:presentname:defaults3_bucket_name:mylogbucketregion:us-east-1is_multi_region_trail:trueenable_log_file_validation:truecloudwatch_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"tags:environment:devName:default