First you start the sample application on Instance A so that it writes log lines, then you query them with Logs Insights.


In the terminal, view the script, start it in the background (1) and check that it is running (2):
cat /opt/fcj/logger.py
nohup python3 /opt/fcj/logger.py > /dev/null 2>&1 &
ps aux | grep [l]ogger.py

The script writes a line every 1 to 4 seconds: mostly INFO, some WARNING and about 15% ERROR. Keep it running until the end of the lab.
Look at the log file. Lines from python-app appear between the system messages (1)(2). Press Ctrl+C to stop tail.
sudo tail -f /var/log/messages

/fcj/cloudwatch (1) and select /fcj/cloudwatch-workshop/var/log/messages (2). Close the selector.
Check that the log group is selected (1), enter the query below (2) and choose Run query (3).
fields @timestamp, @logStream, @message
| filter @message like /python-app/
| sort @timestamp desc
| limit 20

python-app (1)(2).
Logs Insights can also parse and aggregate. Run the query below (1)(2). It extracts the level word after python-app[pid]: and counts the lines per level.
filter @message like /python-app/
| parse @message "python-app[*]: * " as pid, level
| stats count(*) as events by level

ERROR, WARNING and INFO lines (2).