AWS Builder Center
AWS CloudOps Learning Journey | Skill 1.2.1 – Analyze Performance Metrics & Automate Remediation

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)

  1. …
  2. 7
    AWS 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:
  1. Restart an EC2 instance through a Systems Manager Automation runbook.
  1. 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

  1. Open the EC2 Console.
  1. Select your test Linux instance.
  1. Note its Instance ID.
  1. Ensure the instance is running.

Step 2: Create a CloudWatch CPU Alarm

  1. Open the CloudWatch Console.
  1. Navigate to Alarms → Create alarm.
  1. Select Select metric.
  1. Choose EC2 → Per-Instance Metrics.
  1. Select your instance's  CPUUtilization  metric.
  1. Configure:
  • Statistic: Average
  • Period: 1 minute
  • Threshold type: Static
  • Condition: Greater than 70
  1. Configure the alarm to enter  ALARM  when the condition is met.

Step 3: Create a Lambda Function

  1. Open the AWS Lambda Console.
  1. Select Create function.
  1. Choose Author from scratch.
  1. Function name:  EC2-Remediation .
  1. Runtime: Python.
  1. 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 boto3
import 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

  1. Open your CloudWatch alarm.
  1. Choose Actions → Edit.
  1. Under the  ALARM  state action, select the Lambda function.
  1. Choose  EC2-Remediation .
  1. Save the alarm.

Step 8: Verify the Remediation

  1. Generate CPU activity on the test instance.
  1. Wait for the CloudWatch alarm to enter  ALARM .
  1. Open the Lambda Monitor tab and check the invocation.
  1. Open Systems Manager → Automation.
  1. Find the execution of  AWS-RestartEC2Instance .
  1. Check whether the execution succeeded.
  1. 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  StartAutomationExecution  to investigate an Automation request.
  • Check  RebootInstances  to 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:
  1. Which metric indicates the problem?
  1. Is the metric abnormal or within the normal workload pattern?
  1. What is the likely root cause?
  1. Which action is appropriate?
  1. Does the automation have the required IAM permissions?
  1. How will I verify that the remediation succeeded?
  1. What happens if the automated action fails?

9. Cleanup

To avoid unnecessary resources or unexpected restarts:
  1. Delete the CloudWatch alarm.
  1. Delete the Lambda function.
  1. Remove any temporary IAM permissions or roles created for this lab.
  1. Confirm that no Automation execution is still running.
  1. 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)

  1. …
  2. 7
    AWS CloudOps Learning Journey | Skill 1.2.1 – Analyze Performance Metrics & Automate Remediation This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article