📘 How to Send Apache + ModSecurity Logs to AWS CloudWatch Logs on EC2
In this guide, you'll learn how to forward ModSecurity logs from Apache to AWS CloudWatch Logs using the CloudWatch Agent on an EC2 instance with an IAM Role , and ensure it runs reliably using systemd . ✅ Prerequisites An EC2 instance (Ubuntu/Debian) Apache2 and ModSecurity installed Instance has an IAM Role attached with permission: CloudWatchAgentServerPolicy or: { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogStreams" ], "Resource": "*" } ⚙️ Step 1: Install the CloudWatch Agent cd /opt curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i amazon-cloudwatch-agent.deb 🛠️ Step 2: Create the Agent Configuration File Save this file as /opt/cloudwatch-config.json : { "logs": { "logs_colle...