
AWS CloudOps Learning Journey | Skill 1.1.2 Configure and Manage the CloudWatch Agent
Going beyond basic EC2 monitoring to collect system-level metrics and logs using the CloudWatch Agent. Learn how to configure, verify, monitor, and troubleshoot CloudWatch Agent through hands-on demos.
Series: My CloudOps Learning Journey (7 articles)
- …
- 3AWS CloudOps Learning Journey | Skill 1.1.2 Configure and Manage the CloudWatch Agent This article
Skill 1.1.2: Configure and Manage the CloudWatch Agent – Metrics, Logs & Troubleshooting
From monitoring AWS resources to understanding what happens inside them.
AWS Certified CloudOps Engineer – Associate (SOA-C03)
🎯 SKILL OVERVIEW
Official Skill 1.1.2:
"Configure and manage the CloudWatch agent to collect metrics and logs from EC2 instances, Amazon ECS clusters, or Amazon EKS clusters."
In the previous article, we explored CloudWatch workload monitoring using EC2 metrics and dashboards.
But there is an important limitation.
Imagine an EC2 instance is running normally, and CloudWatch displays its CPU utilization. However, the operations team also wants to know:
- How much memory is being used inside the operating system?
- Is disk space running low?
- What errors are appearing in the application logs?
- Why is the application behaving unexpectedly?
Basic EC2 monitoring does not provide all this operating-system-level information.
This is where the Amazon CloudWatch Agent becomes important.
In this article, we'll understand the CloudWatch Agent and practise two hands-on demonstrations.
☁️ 1. WHY DO WE NEED THE CLOUDWATCH AGENT?
Consider an application running on an Amazon EC2 instance.
CloudWatch already provides standard EC2 metrics such as:
- CPUUtilization
- NetworkIn
- NetworkOut
- DiskReadOps
- DiskWriteOps
However, the operations team needs additional information from inside the operating system.
For example:
- Memory utilization
- Filesystem usage
- Operating-system-level metrics
- Application log files
The CloudWatch Agent collects this additional information and sends it to AWS monitoring services.
Remember:
CloudWatch helps monitor AWS resources. The CloudWatch Agent helps collect additional information from inside the server.
2. WHAT IS THE CLOUDWATCH AGENT?
The Amazon CloudWatch Agent is software installed on an EC2 instance or supported server.
It collects configured system-level metrics and log events and sends them to AWS.
Important components
Component | Purpose |
|---|---|
CloudWatch Agent | Collects metrics and logs |
Agent configuration | Defines what information to collect |
IAM role | Provides permissions to publish data |
CloudWatch Metrics | Stores and displays collected metrics |
CloudWatch Logs | Stores collected log events |
Understand the difference
Example 1 – Memory monitoring
The CloudWatch Agent collects memory utilization and publishes it under the
CWAgent namespace by default.Example 2 – Application log monitoring
The agent reads a configured log file and sends its events to a CloudWatch Logs log group.
🔧 3. PRACTICAL DEMO – CLOUDWATCH AGENT: MEMORY AND LOGS
Scenario:
An application is running on an EC2 instance. The operations team wants to monitor memory utilization and collect application/system logs.
Objective:
Install and configure the CloudWatch Agent, verify that metrics and logs arrive in CloudWatch, and troubleshoot missing data.
STEP 1 – UNDERSTAND THE SCENARIO
Imagine users report that an application is becoming slow.
The CloudOps engineer needs to investigate:
- Is memory utilization increasing?
- Is the server running out of resources?
- Are there errors in the application logs?
CPU metrics alone cannot answer all these questions.
We need additional monitoring information from inside the EC2 instance.
STEP 2 – PREPARE THE ENVIRONMENT
For this exercise, use a small Amazon Linux EC2 instance in a dedicated lab environment.
Before starting:
- Select the correct AWS Region.
- Ensure the instance has a suitable IAM role.
- Attach the
CloudWatchAgentServerPolicymanaged policy to the instance role, following least-privilege requirements.
- If using Systems Manager, also configure the required Systems Manager permissions and connectivity.
- Confirm that the instance can reach the required AWS endpoints.
Do not use long-lived access keys inside the instance.
STEP 3 – INSTALL THE CLOUDWATCH AGENT
You can install the CloudWatch Agent using AWS Systems Manager or the appropriate package installation method for your operating system.
For an SSM-managed EC2 instance:
- Open Systems Manager.
- Select Run Command.
- Choose
AWS-ConfigureAWSPackage.
- Select the
AmazonCloudWatchAgentpackage.
- Choose the Install action.
- Select your lab EC2 instance.
- Run the command and inspect its output.
Confirm that the installation succeeds before proceeding.
STEP 4 – CONFIGURE METRICS AND LOGS
Create an agent configuration that specifies:
- Memory utilization metrics.
- The log file to collect.
- The CloudWatch Logs destination.
- The collection interval.
For example, a Linux configuration can include:
{ "metrics": { "namespace": "CWAgent", "metrics_collected": { "mem": { "measurement": [ "mem_used_percent" ], "metrics_collection_interval": 60 } } }, "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/messages", "log_group_name": "/cloudops/ec2/system", "log_stream_name": "{instance_id}" } ] } } }}This is an example configuration for a Linux system where
/var/log/messages exists.The log file path must match the actual operating system and application.
STEP 5 – START THE AGENT
After saving the configuration, start the CloudWatch Agent.
For a configuration file saved at the standard Linux agent configuration path:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \-a fetch-config \-m ec2 \-c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json \-sCheck the service:
sudo systemctl status amazon-cloudwatch-agentExpected result: The CloudWatch Agent service is running.
STEP 6 – GENERATE TEST DATA
Generate normal memory activity on the instance.
Write a test log entry:
logger "CloudOps Demo 02 test log entry"Check the local log file to confirm that the entry was recorded.
Allow time for the agent to collect and publish the information.
STEP 7 – VERIFY THE WORKING STATE
Open CloudWatch.
For metrics:
CloudWatch → Metrics → All metrics → CWAgent
Look for:
mem_used_percent For logs:
CloudWatch → Logs → Log groups
Open:
/cloudops/ec2/system Check whether the test log entry appears in the expected log stream.
Expected result:
- Memory utilization metric is available.
- Log group exists.
- Log stream contains the test event.
- Agent service is running.
Capture evidence of the working configuration.
STEP 8 – DELIBERATELY BREAK IT
Now introduce one controlled fault.
Fault: Stop the CloudWatch Agent service.
sudo systemctl stop amazon-cloudwatch-agentDo not change any other configuration.
STEP 9 – OBSERVE THE FAILURE
Expected symptom:
Memory metrics and/or log events stop arriving in CloudWatch.
The EC2 instance itself may still be running normally.
Think about this:
- Is the EC2 instance stopped? No.
- Is the agent running? No.
- Can the agent continue publishing information? No.
The failure is at the agent layer.
STEP 10 – TROUBLESHOOT AND FIX
Check the agent service:
sudo systemctl status amazon-cloudwatch-agentIf stopped, restart it:
sudo systemctl start amazon-cloudwatch-agentCheck its local logs:
sudo tail -n 50 /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.logVerify the service is running and wait for fresh metrics and log events.
Expected recovery: Memory metrics and log events resume arriving in CloudWatch.
🔍 4. PRACTICAL DEMO 03 – CLOUDWATCH AGENT TROUBLESHOOTING
Scenario:
A previously working CloudWatch Agent has stopped publishing memory metrics and application logs.
The EC2 instance is healthy, but CloudWatch data is missing.
Objective:
Identify whether the issue is caused by the agent service, configuration, log file path or IAM permissions.
STEP 1 – ESTABLISH A WORKING BASELINE
Before introducing a failure:
- Verify the agent service is running.
- Confirm the configuration location.
- Check that memory metrics arrive.
- Confirm that logs appear in CloudWatch.
- Record the current configuration.
A known-good baseline helps identify what changed.
STEP 2 – INTRODUCE ONE CONTROLLED FAULT
Practise these failures separately:
- Invalid JSON in the agent configuration.
- Incorrect log file path.
- Stopped CloudWatch Agent.
- Insufficient instance IAM permissions.
Do not introduce multiple failures simultaneously.
STEP 3 – OBSERVE THE SYMPTOM
The EC2 instance is healthy, but CloudWatch metrics or logs are missing.
This does not automatically mean CloudWatch itself is unavailable.
The problem could exist inside the EC2 instance or in its communication with AWS.
STEP 4 – TROUBLESHOOT THE FAILURE
CASE 1 – CloudWatch Agent service is stopped
Symptom: Metrics and logs stop arriving.
What to check:
sudo systemctl status amazon-cloudwatch-agentPossible root cause: The agent service stopped or failed to start.
Solution:
sudo systemctl start amazon-cloudwatch-agentVerify: Confirm service status and check for fresh data.
CASE 2 – Invalid JSON configuration
Symptom: The agent fails to start or does not load the intended configuration.
What to check:
Inspect the configuration file:
sudo cat /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.jsonCheck the agent logs:
sudo tail -n 50 /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.logPossible root cause: Missing commas, incorrect quotation marks, invalid JSON structure or unsupported configuration values.
Solution: Correct the configuration and validate it before restarting the agent.
You can use a JSON validator where available:
python3 -m json.tool /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.jsonThen reload the configuration using the CloudWatch Agent control command.
Verify: Confirm that the agent starts successfully and fresh data arrives.
CASE 3 – Wrong log file path
Symptom: Memory metrics arrive, but application/system logs are missing.
What to check:
sudo ls -l /var/log/Check the configured
file_path in the agent configuration.Possible root cause: The agent is monitoring a file that does not exist or is not the actual application log file.
Solution: Correct the file path to the real log file.
Verify: Generate a new log entry and confirm that it appears in the correct CloudWatch Logs stream.
CASE 4 – Insufficient IAM permissions
Symptom: The agent is running, but metrics or logs cannot be published to AWS.
What to check:
- Is the correct IAM role attached to the EC2 instance?
- Does the role provide the required CloudWatch permissions?
- Are there permission-denying policies or restrictions?
- Do the agent logs show authorization errors?
Possible root cause: Missing permissions such as
cloudwatch:PutMetricData or required CloudWatch Logs actions.Solution: Attach or correct the appropriate permissions, such as the AWS-managed
CloudWatchAgentServerPolicy , after reviewing the role's existing policies.Verify: Check the agent logs and confirm that new metrics and log events arrive.
CASE 5 – EC2 is healthy, but neither metrics nor logs arrive
Symptom: The instance is running, but both types of agent data are missing.
What to check:
- Agent service status.
- Agent configuration.
- Local agent logs.
- IAM permissions.
- Network connectivity to the required AWS endpoints.
Possible root causes: A stopped agent, invalid configuration, permission failure or connectivity problem.
Solution: Identify the failing layer using evidence. Fix only the confirmed root cause.
Verify: Confirm that both metrics and logs resume arriving.
STEP 5 – VERIFY RECOVERY
After fixing a failure, confirm:
- Agent service is running.
- Configuration is valid.
- Memory metrics are visible.
- Log events are arriving.
- No new relevant errors appear in the agent logs.
A successful command is not enough. The actual monitoring data must return.
STEP 6 – CLEAN UP
- Remove test log entries or unnecessary test resources where appropriate.
- Stop or terminate lab EC2 instances when no longer needed.
- Remove unused lab configurations and resources.
- Check for any ongoing charges.
Remember that CloudWatch custom metrics and CloudWatch Logs have associated pricing.
🧠 5. QUICK TROUBLESHOOTING REFERENCE
Problem | What to check | Solution |
|---|---|---|
No metrics or logs | Agent service status | Start or repair the agent |
Agent fails to start | Configuration and local logs | Correct configuration |
Memory metric missing | Metrics configuration and IAM | Enable memory collection and fix permissions |
Logs missing | Log file path and file availability | Configure the correct path |
Authorization error | EC2 instance IAM role | Correct required permissions |
Both metrics and logs missing | Agent, IAM and connectivity | Identify and fix the failing layer |
Data missing after restart | Agent startup and configuration persistence | Restore the intended configuration and startup behavior |
📝 6. EXAM CONNECTION
If the question describes... | Remember... |
|---|---|
Collecting EC2 memory utilization | CloudWatch Agent |
Collecting operating-system-level metrics | CloudWatch Agent |
Sending application log files to AWS | CloudWatch Agent + CloudWatch Logs |
Missing metrics while EC2 is healthy | Check agent, configuration and permissions |
Agent cannot publish metrics | Check IAM permissions |
Metrics available but logs missing | Check log collection configuration and file path |
Default EC2 CPU monitoring | CloudWatch EC2 metrics |
Important distinction
- CloudWatch standard EC2 metrics: Resource-level monitoring.
- CloudWatch Agent: Additional system-level metrics and log collection.
- CloudWatch Logs: Storage and analysis of log events.
- IAM role: Permissions that allow the agent to publish information.
✅ 7. WHAT HAVE WE LEARNED?
After completing these demonstrations, you should be able to:
- Explain why the CloudWatch Agent is needed.
- Install the agent on an EC2 instance.
- Configure memory metrics.
- Configure log collection.
- Understand the
CWAgentnamespace.
- Verify metrics and logs in CloudWatch.
- Troubleshoot a stopped agent.
- Identify invalid JSON and incorrect log paths.
- Investigate IAM permission failures.
- Verify recovery using actual CloudWatch data.
THE CLOUDOPS MINDSET
Don't stop at checking whether an EC2 instance is running.
A healthy EC2 instance does not guarantee that monitoring is working.
A CloudOps engineer must understand the agent, its configuration, permissions and connectivity — and use evidence to identify exactly why monitoring data is missing.
Next: Skill 1.1.3 – Configure, Identify and Troubleshoot CloudWatch Alarms.
☁️ Learn • Practise • Troubleshoot • Fix • Verify • Grow
Series: My CloudOps Learning Journey (7 articles)
- …
- 3AWS CloudOps Learning Journey | Skill 1.1.2 Configure and Manage the CloudWatch Agent This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article