
AWS CloudOps Learning Journey | Skill 1.2.1 – Analyze Performance Metrics & Automate Remediation
Learn how CloudWatch, Lambda, and Systems Manager work together to detect performance issues and automate corrective actions.
Series: My CloudOps Learning Journey (7 articles)
- …
- 7AWS CloudOps Learning Journey | Skill 1.2.1 – Analyze Performance Metrics & Automate Remediation This article
1. Why Do We Need Automated Remediation?
Imagine you are managing an EC2 instance hosting a website.
Suddenly:
- CPU utilization becomes very high.
- Website response time increases.
- Users start experiencing delays.
A CloudOps engineer must identify the problem and take corrective action.
Traditionally, an administrator checks the metrics, investigates the issue, connects to the server, and performs the required action manually.
But what if AWS could detect the issue and automatically start a predefined corrective action?
This is called Automated Remediation.
It helps reduce manual effort, improve response time, and maintain reliable workloads.
2. Understand the Core Concepts
A. Performance Metrics
A metric is a numerical measurement used to understand the performance and health of an AWS resource.
Examples:
Metric | What it tells us |
|---|---|
CPUUtilization | How much CPU is being used |
MemoryUtilization | How much memory is being used |
NetworkIn / NetworkOut | Network traffic received and sent |
DiskReadOps / DiskWriteOps | Disk read and write operations |
StatusCheckFailed | Whether an EC2 status check has failed |
Example 1: CPU utilization continuously stays above 80%. This may indicate that the instance is under heavy processing load.
Example 2: Memory utilization reaches 95%. The application may experience memory pressure or become unresponsive.
Note: EC2 provides basic CPU, network, and status-check metrics. Memory and disk-space utilization generally require the CloudWatch Agent or another monitoring method.
B. Performance Analysis
Collecting metrics is not enough. We must interpret them to identify possible problems.
For example:
- High CPU + increased response time → investigate processing load.
- High memory + application errors → investigate memory pressure.
A metric indicates what is happening, but it does not always explain the root cause. Check logs, resource activity, and recent changes before deciding on remediation.
C. Automated Remediation
Automated remediation means using AWS services to perform predefined corrective actions when a problem is detected.
Examples:
- Restart an EC2 instance through a Systems Manager Automation runbook.
- Invoke a Lambda function when a CloudWatch alarm enters the ALARM state.
The action should be selected according to the actual problem. Automatically restarting every resource with high CPU is not a good production strategy.
3. AWS Services Used
AWS Service | Role in this skill |
|---|---|
Amazon CloudWatch | Collects metrics and detects abnormal conditions |
AWS Lambda | Executes custom remediation logic |
AWS Systems Manager Automation | Runs predefined or custom operational runbooks |
AWS CloudTrail | Helps investigate API activity and changes |
Kiro | Listed in the exam guide as an example of AWS functionality |
AWS DevOps Agent | Listed in the exam guide as an example of AWS functionality |
How They Work Together
EC2 → CloudWatch Metrics → CloudWatch Alarm → Lambda → Systems Manager Automation → Remediation CloudTrail helps investigate the activity surrounding the incident and the actions performed.
4. CloudWatch Anomaly Detection
A fixed threshold is not always suitable for every workload.
For example, CPU utilization of 70% might be normal during business hours but unusual at midnight.
CloudWatch Anomaly Detection uses statistical and machine learning algorithms to learn normal metric patterns and generate an expected range.
Two ways to use it:
- Create an anomaly detection alarm.
- Display the expected range as a band on a metric graph.
Remember: Anomaly detection is useful when normal workload patterns change over time. It does not automatically identify the root cause or fix the problem.
5. Hands-On Demo – Automate EC2 Remediation
Objective: Configure a CloudWatch alarm to invoke Lambda, which starts an AWS Systems Manager Automation runbook to restart a test EC2 instance.
<text>⚠️ Lab safety: Restarting an instance interrupts its running workloads. Use only a test EC2 instance, not a production server. A high CPU reading alone does not prove that restarting is the correct fix.</text>
Step 1: Prepare the EC2 instance
- Open the EC2 Console.
- Select your test Linux instance.
- Note its Instance ID.
- Ensure the instance is running.
Step 2: Create a CloudWatch CPU Alarm
- Open the CloudWatch Console.
- Navigate to Alarms → Create alarm.
- Select Select metric.
- Choose EC2 → Per-Instance Metrics.
- Select your instance's
CPUUtilizationmetric.
- Configure:
- Statistic: Average
- Period: 1 minute
- Threshold type: Static
- Condition: Greater than 70
- Configure the alarm to enter
ALARMwhen the condition is met.
Step 3: Create a Lambda Function
- Open the AWS Lambda Console.
- Select Create function.
- Choose Author from scratch.
- Function name:
EC2-Remediation.
- Runtime: Python.
- Create the function.
Step 4: Add Lambda Code
The Lambda function will start the AWS-managed Systems Manager runbook
AWS-RestartEC2Instance .Set an environment variable named
INSTANCE_ID containing your test EC2 instance ID.Use this code:
import boto3import os
ssm = boto3.client("ssm")
def lambda_handler(event, context):
state = event.get("alarmData", {}).get("state", {}).get("value")
if state != "ALARM": return {"message": "No remediation required"}
instance_id = os.environ["INSTANCE_ID"]
response = ssm.start_automation_execution( DocumentName="AWS-RestartEC2Instance", Parameters={ "InstanceId": [instance_id] } )
return { "message": "Remediation started", "execution_id": response["AutomationExecutionId"] }Step 5: Configure IAM Permissions
The Lambda execution role needs permission to:
- Start the Systems Manager Automation runbook using
ssm:StartAutomationExecution.
- Reboot the specified EC2 instance using
ec2:RebootInstances.
For this example, the runbook does not specify an
AutomationAssumeRole , so it uses the calling identity's permissions. In production, use a dedicated, least-privilege Automation role and explicitly pass it when required.Step 6: Allow CloudWatch to Invoke Lambda
CloudWatch must have permission to invoke the Lambda function.
You can configure this when adding the Lambda function as an alarm action, or use the Lambda resource policy.
Step 7: Connect Lambda to the Alarm
- Open your CloudWatch alarm.
- Choose Actions → Edit.
- Under the
ALARMstate action, select the Lambda function.
- Choose
EC2-Remediation.
- Save the alarm.
Step 8: Verify the Remediation
- Generate CPU activity on the test instance.
- Wait for the CloudWatch alarm to enter
ALARM.
- Open the Lambda Monitor tab and check the invocation.
- Open Systems Manager → Automation.
- Find the execution of
AWS-RestartEC2Instance.
- Check whether the execution succeeded.
- Verify the EC2 instance returns to the running state.
Expected workflow:
High CPU → CloudWatch ALARM → Lambda Invocation → SSM Automation → EC2 Restart This is a controlled demonstration of metric-based automated remediation, not a recommendation to restart instances whenever CPU is high.
6. Troubleshooting
Problem | What to check | Possible solution |
|---|---|---|
Alarm does not trigger | Metric and threshold | Verify CPU metric and evaluation settings |
Lambda is not invoked | Lambda resource policy | Allow CloudWatch alarm invocation |
Lambda reports AccessDenied | Execution role | Check SSM and EC2 permissions |
Automation does not start | Runbook name and parameters | Verify document name and Instance ID |
Automation fails | Execution steps and IAM permissions | Inspect the Automation execution details |
Instance does not restart | EC2 state and permissions | Check EC2 permissions and instance state |
CPU remains high after restart | Application and system logs | Investigate the actual root cause |
Investigate Using CloudTrail
CloudTrail helps identify who performed an action, what API operation was called, and when it happened.
For example:
- Check
StartAutomationExecutionto investigate an Automation request.
- Check
RebootInstancesto investigate an EC2 reboot request.
Event history provides the past 90 days of management events in a Region. It does not display data events.
7. Important Exam Revision
Concept | Remember |
|---|---|
Performance Metrics | Measurements of resource performance |
CloudWatch Alarm | Detects a configured metric condition |
Anomaly Detection | Learns expected metric patterns |
Lambda | Executes custom code |
Systems Manager Automation | Executes operational runbooks |
CloudTrail | Records and helps investigate API activity |
Automated Remediation | Automatically performs corrective actions |
IAM Permissions | Control which actions automation can perform |
Important Differences
CloudWatch vs CloudTrail
- CloudWatch: Monitors resource performance and health.
- CloudTrail: Records account and API activity.
Lambda vs Systems Manager Automation
- Lambda: Runs custom code.
- Systems Manager Automation: Executes predefined or custom operational runbooks.
Monitoring vs Remediation
- Monitoring identifies a problem.
- Remediation performs an action to address it.
8. Decision Notebook
Before automating a corrective action, ask:
- Which metric indicates the problem?
- Is the metric abnormal or within the normal workload pattern?
- What is the likely root cause?
- Which action is appropriate?
- Does the automation have the required IAM permissions?
- How will I verify that the remediation succeeded?
- What happens if the automated action fails?
9. Cleanup
To avoid unnecessary resources or unexpected restarts:
- Delete the CloudWatch alarm.
- Delete the Lambda function.
- Remove any temporary IAM permissions or roles created for this lab.
- Confirm that no Automation execution is still running.
- Stop or terminate the EC2 instance if it was created only for testing.
10. Official AWS Documentation
Next Skill: Skill 1.2.2 – Use EventBridge to route, enrich, and deliver events, and troubleshoot any issues with event bus rules.
Series: My CloudOps Learning Journey (7 articles)
- …
- 7AWS CloudOps Learning Journey | Skill 1.2.1 – Analyze Performance Metrics & Automate Remediation 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