- Lab
- A Cloud Guru
Standing Up an Apache Web Server EC2 Instance and Sending Logs to Amazon CloudWatch
During this hands-on lab project you are going to work on configuring an Amazon EC2 instance to push some custom log files to Amazon CloudWatch using the CloudWatch agent. Once the log files are correctly configured to be sent to Amazon CloudWatch, you will then implement a simple alerting system to catch some specific warnings and error messages using Metric Filters and Amazon SNS notifications.
Path Info
Table of Contents
-
Challenge
Install and Configure the Amazon CloudWatch Agent
Connect to the ApacheWebServer EC2 instance using Session Manager.
Once connected, use the commands listed in the lab GitHub repo to install the Amazon CloudWatch agent and create the agent configuration file.
Copy and paste the JSON configuration code into the new file then start the agent with the new config file using the command listed on GitHub.
-
Challenge
Create a Metric Filter for 404 Status Codes
Within the Amazon CloudWatch Apache-Access-Logs Log Group, create a new metric filter looking for
404
status codes within the log entries.For the Filter pattern enter the following text to create a metric filter that matches for any 404 status codes.
%\b404\b%
Metric Filter Settings:
- Filter Name:
404
- Metric namespace:
Apache
- Metric name:
404
- Metric value: 1
- Default value: blank
- Unit: Count
For testing, open the public IP of the ApacheWebServer instance in your browser, change the URL to http and append a fake page on the end (Example: http://YOUR_PUBLIC_IP/fake.html).
- Filter Name:
-
Challenge
Create SNS Topic and CloudWatch Alarm
Now, we can put it all together and set up a new CloudWatch Alarm to send a message through Amazon SNS to notify us whenever a
404
is detected in our Log Group.Create a new alarm via the CloudWatch Alarms dashboard for the newly created Apache namespace.
Hint: There is a shortcut from within the graphed metric section.
Alarm Metric Settings:
- Metric namespace:
Apache
- Metric name:
404
- Statistic:
Sum
Alarm Conditions Settings:
- Threshold type: Static
- Whenever 404 is...: Greater/Equal
- than: 0
- Alarm state trigger: In alarm
- Alarm name:
404-Detections
Then, create a new SNS topic named
404-Alerts
and confirm subscription to it. Refresh the fake ApacheWebServer page to generate 404 errors and test the alarm. - Metric namespace:
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.