AWS Classroomnotes 22/Dec/2021

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

Preview
* Continue with settings till you reach the log files section. configure for access logs
Preview
* Now configure for error logs
Preview
Preview
* Now we need to inform the cloudwatch agent whihc configuration to use
Preview

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

Preview
* Sample script to generate traffic

#!/bin/bash
apache_url='http://18.237.201.9/'
while true
do
curl ${apache_url}
sleep 5
done

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner