BrainyBeeBrainyBee
ExploreBlogStart Studying
HomeAWS Certified DevOps Engineer - Professional (DOP-C02)Lab: Detecting Issues through Log Analysis and Metric Monitoring
Hands-On Lab1,050 words

Lab: Detecting Issues through Log Analysis and Metric Monitoring

Audit, monitor, and analyze logs and metrics to detect issues

Lab: Detecting Issues through Log Analysis and Metric Monitoring

This hands-on lab guides you through the process of auditing, monitoring, and analyzing AWS logs and metrics to detect operational issues. You will implement CloudWatch Metric Filters, configure Anomaly Detection Alarms, and perform deep-dive analysis using CloudWatch Logs Insights.

Prerequisites

To successfully complete this lab, you need:

  • An AWS Account with administrative access or permissions for cloudwatch:*, logs:*, and sns:*.
  • AWS CLI installed and configured on your local machine with access to <YOUR_REGION>.
  • Basic familiarity with JSON and log patterns.
  • IAM Permissions: Ensure your user/role has iam:CreateRole and iam:PassRole if deploying supplementary compute (though this lab focuses on direct log ingestion).

Learning Objectives

By the end of this lab, you will be able to:

  1. Create CloudWatch Metric Filters to extract numerical data from unstructured logs.
  2. Configure CloudWatch Alarms utilizing Anomaly Detection to identify unusual patterns.
  3. Execute complex log queries using CloudWatch Logs Insights for root cause analysis.
  4. Build a basic CloudWatch Dashboard to visualize real-time health metrics.

Architecture Overview

The following diagram illustrates the flow of log data from ingestion to actionable detection.

Loading Diagram...
Figure 1 — Mermaid diagram

Step-by-Step Instructions

Step 1: Create a Log Group and Stream

We will start by creating a destination for our application logs.

CLI Option:

bash
aws logs create-log-group --log-group-name "/aws/devops/application-logs" aws logs create-log-stream --log-group-name "/aws/devops/application-logs" --log-stream-name "AppInstance01"
▶Console alternative
  1. Navigate to CloudWatch > Logs > Log groups.
  2. Click Create log group.
  3. Name it /aws/devops/application-logs and click Create.
  4. Click into the new log group and select Create log stream named AppInstance01.

Step 2: Configure a Metric Filter for Error Detection

We need to track how many 404 Not Found errors occur. We will create a filter that looks for the string "404".

CLI Option:

bash
aws logs put-metric-filter \ --log-group-name "/aws/devops/application-logs" \ --filter-name "404ErrorFilter" \ --filter-pattern "404" \ --metric-transformations \ metricName="NotFoundCount",metricNamespace="MyApplication",metricValue="1"
▶Console alternative
  1. In your Log Group, go to the Metric filters tab and click Create metric filter.
  2. In Filter pattern, type "404".
  3. Click Next. Name the filter 404ErrorFilter.
  4. For Metric namespace, enter MyApplication. For Metric name, enter NotFoundCount. For Metric value, enter 1.
  5. Click Create metric filter.

Step 3: Enable Anomaly Detection on the Metric

Instead of a static threshold, we will use machine learning to detect "unusual" spikes in 404 errors.

CLI Option:

bash
aws cloudwatch put-metric-alarm \ --alarm-name "AnomalyDetection-404" \ --comparison-operator "GreaterThanUpperThreshold" \ --evaluation-periods 2 \ --threshold-metric-id "e1" \ --metrics '[{"Id":"m1","MetricStat":{"Metric":{"Namespace":"MyApplication","MetricName":"NotFoundCount"},"Period":60,"Stat":"Sum"},"ReturnData":true},{"Id":"e1","Expression":"ANOMALY_DETECTION_BAND(m1, 2)","Label":"NotFoundCount (Expected)","ReturnData":true}]'

[!NOTE] The 2 in ANOMALY_DETECTION_BAND(m1, 2) represents the standard deviation. A lower number makes the alarm more sensitive.

Step 4: Generate Simulated Log Data

We need data to see the filter and anomaly detection in action.

CLI Only:

bash
# Run this a few times to simulate 404 errors aws logs put-log-events \ --log-group-name "/aws/devops/application-logs" \ --log-stream-name "AppInstance01" \ --log-events '[{"timestamp":'$(date +%s000)',"message":"ERROR: User requested /page-not-found - 404"}]'

Step 5: Analyze Logs with CloudWatch Logs Insights

When an alarm triggers, you need to find the specific log entries. Use Insights to query them.

Console Only:

  1. Navigate to CloudWatch > Logs > Logs Insights.
  2. Select your log group /aws/devops/application-logs.
  3. Run the following query:
sql
fields @timestamp, @message | filter @message like /404/ | sort @timestamp desc | limit 20

Checkpoints

CheckpointValidation ActionExpected Result
Log Groupaws logs describe-log-groupsLog group exists in list
Metric Filteraws logs describe-metric-filters404ErrorFilter is listed
Alarm StatusView Alarms in ConsoleAlarm state is OK or ALARM (not INSUFFICIENT_DATA after a few mins)

Teardown

[!WARNING] Always delete resources after lab completion to prevent unexpected billing.

CLI Commands:

bash
# 1. Delete the Alarm aws cloudwatch delete-alarms --alarm-names "AnomalyDetection-404" # 2. Delete the Log Group (This deletes all streams and filters within it) aws logs delete-log-group --log-group-name "/aws/devops/application-logs"

Troubleshooting

IssuePossible CauseFix
No data in Metric FilterPattern mismatchEnsure the string in logs exactly matches the pattern (e.g., case sensitivity)
Alarm stays in INSUFFICIENT_DATANot enough samplesAnomaly detection requires at least 3-12 hours of historical data to be fully accurate, though it will start showing bands sooner
CLI Auth ErrorsExpired credentialsRun aws configure or check ~/.aws/credentials

Stretch Challenge

Task: Create a CloudWatch Dashboard named Application-Health and add a Stacked Area widget that displays the NotFoundCount metric alongside standard AWS/EC2 CPUUtilization (if you have an instance running) or any other existing metric.

Cost Estimate

  • CloudWatch Logs Ingestion: $0.50 per GB (Free tier covers 5GB/month).
  • CloudWatch Custom Metrics: $0.30 per metric/month (First 10 free).
  • CloudWatch Alarms: $0.10 per alarm/month (First 10 free).
  • Anomaly Detection: Standard alarm pricing applies.
  • Total Estimated Spend: <$0.05 for a 30-minute lab session.

Concept Review

To detect issues effectively, DevOps engineers must move from reactive monitoring (static thresholds) to proactive observability (anomaly detection).

Compiling TikZ diagram…
⏳
Running TeX engine…
This may take a few seconds
Figure 2 — TikZ diagram
  • Metric Filters: Bridge the gap between text logs and numeric monitoring.
  • Anomaly Detection: Dynamically adjusts to seasonal trends (e.g., higher traffic on Mondays).
  • Logs Insights: High-performance querying for pinpointing errors within millions of lines of logs.
All AWS Certified DevOps Engineer - Professional (DOP-C02) Study Resources

Related Notes

  • Examining Observability: Auditing, Monitoring, and Analyzing Logs and Metrics925 words
  • Mastering AWS Alerting and Automated Remediation1,050 words
  • Study Guide: Analyzing Failed Deployments in AWS940 words
  • Incident Analysis: Troubleshooting Failed Processes in AWS1,050 words
  • Mastering AWS Monitoring & Security Analytics: Logs, Metrics, and Findings1,050 words
  • AWS Log Analysis: Athena, CloudWatch Insights, and OpenSearch920 words
  • Analyzing Real-Time Log Streams with Amazon Kinesis Data Streams985 words
  • CloudWatch Anomaly Detection Alarms: Professional Study Guide820 words
  • AWS Application Storage Patterns: EBS, EFS, and S31,054 words
  • Lab: Automating Security Controls and Data Protection with AWS Secrets Manager and Config942 words
  • Master Study Guide: Automating Security Controls & Data Protection (AWS DOP-C02)1,184 words
  • Mastering AWS CloudFormation StackSets: Multi-Account & Multi-Region Orchestration895 words

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up.

Start Studying

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free
AWS Certified DevOps Engineer - Professional (DOP-C02) ResourcesExplore All HivesBlogHome

© 2026 BrainyBee. Free AI-powered exam prep.

Loading Diagram...
Flowchart, top to bottom. Log Producer (Simulated Application) connects to CloudWatch Log Group. B connects to Metric Filter. C connects to CloudWatch Custom Metric. D connects to Anomaly Detection Alarm. E connects to Alert Notification ("Breach"). B connects to CloudWatch Logs Insights. D connects to CloudWatch Dashboard.