Uploading Apache Logs to CloudWatch
- Create an ec2 instance with Amazon linux
- Ensure IAM role is given to ec2 instance post launch
- Now login into the ec2 instance and install apache server
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
- The path for the apache logs are
/var/log/httpd/access_log
and/var/log/httpd/error_log
- Now lets install cloudwatch agent
sudo yum install amazon-cloudwatch-agent -y
- Now configure cloudwatch agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
* Continue with settings till you reach the log files section. configure for access logs
* Now configure for error logs
* Now we need to inform the cloudwatch agent whihc configuration to use
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
- Now enable and start the cloudwatch agent
sudo systemctl enable amazon-cloudwatch-agent.service
sudo systemctl start amazon-cloudwatch-agent.service
* Sample script to generate traffic
#!/bin/bash
apache_url='http://18.237.201.9/'
while true
do
curl ${apache_url}
sleep 5
done