How CloudWatch receives entries from simulated log

Farzanajuthi
3 min readNov 21, 2023

This is the fifth phase of this project. This phase is a combination of three tasks. I will show every task step by step.

In this phase, you will see how CloudWatch receives data from simulated log.

Task 1: Analyzing the simulated log file

There is a folder, named “samplelogs” in the left side menu in Cloud9. To see a few lines from it, run the following command —

cat samplelogs/access_log.log | head
Few lines in simulated log

To see first line of the log, run this command -

cat samplelogs/access_log.log | head -1 | python -m json.tool

Then if you want to see how many lines in this file, run this command -

cat samplelogs/access_log.log| wc -l

Task 2: Using the new log file

First you have to stop your CloudWatch agent. Run following command —

 sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop

Then check it’s status —

sudo service amazon-cloudwatch-agent status
Inactive CloudWatch Agent

Now you have to keep this simulated log file into the folder where CloudWatch expects it. In phase three, I show there is a configuration file where it states that CloudWatch will expect it’s access log into /var/log/www/access/*. See the following image —

Access log path

So, you have to copy your simulated log file into this folder. You can do that by running following command —

sudo cp /home/ec2-user/environment/samplelogs/access_log.log /var/log/www/access/access_log
Copy access log to var log

Now, it’s time to restart your Cloud agent again —

 sudo systemctl restart amazon-cloudwatch-agent.service

Check status —

sudo service amazon-cloudwatch-agent status
Running state

Task 3: Confirming that the new logs appear in the CloudWatch log group

First, you have to CloudWatch console page. Then choose “Log groups” from it and double click on “apache/access” folder.

Log groups

You will see a generated log file into this folder.

log file

After clicking on log file you will see detail information of the log.

Detail log information

Congratulations!!! You have done one more phase. Go to next phase.

If you find this post helpful, please give a clap in this post and follow me in medium and lets connected in linked in.

--

--

Farzanajuthi

I am an AWS community builder. I have passed AWS certified solution architect (CO3) exam). I love serverless technology and also share knowledge with others.