AWS Cloud Monitoring & Alerting:
EC2 Stress Test Simulation
As a associate system administrator I worked on Redhat Linux servers, including user management, permissions, services, and performance monitoring Automated routine administrative tasks using Bash scripting and cron jobs, reducing manual effort by ~30% I am aws certified sysops administrator and Google Certified Cloud Engineer. Determined to transition my career into cloud architect /Cloud Support role
This project demonstrates how to monitor AWS infrastructure using Amazon CloudWatch and Amazon SNS. You will launch a Linux EC2 instance, install a stress utility to simulate high CPU utilization, and configure automated email alerts to trigger when performance thresholds are breached.
🚀 Project Overview
In a production environment, knowing when your resources are under pressure is critical. This hands-on guide covers:
Launching and configuring an AWS EC2 instance.
Generating artificial CPU load using the
stressutility.Monitoring real-time metrics in CloudWatch.
Configuring CloudWatch Alarms and SNS Notifications for automated alerting.
AWS Services Used
EC2 (Elastic Compute Cloud): To host the Linux environment.
CloudWatch: To monitor CPU utilization and host the alarm logic.
SNS (Simple Notification Service): To send email alerts when the alarm triggers.
Security Groups: To manage access to the instance.
🛠️ Step-by-Step Implementation
Phase 1: Launch the EC2 Instance
Log in to the AWS Management Console.
Navigate to EC2 > Launch Instance.
Name:
Monitoring-Demo-Server.AMI: Amazon Linux 2023 (Free Tier eligible).
Instance Type:
t2.micro.Key Pair: Select an existing one or create a new one to SSH into the instance.
Security Group: Ensure SSH (Port 22) is allowed from your IP.
Phase 2: Create the SNS Topic for Alerts
Before creating the alarm, we need a way to receive notifications.
Go to Amazon SNS > Topics > Create topic.
Type: Standard. Name:
CPU_Alert_Topic.Once created, click Create subscription.
Protocol: Email.
Endpoint: Enter your personal email address.
Important: Check your email inbox and click Confirm Subscription.
Phase 3: Install Stress Utility and Generate Load
Connect to your instance via SSH or EC2 Instance Connect and run the following commands:
Bash
# Update the package index
sudo yum update -y
# Install the stress utility
# Note: For Amazon Linux 2023, you may need to install epel-release or use:
sudo amazon-linux-extras install epel -y # (For AL2)
sudo yum install stress -y
# Verify installation
stress --version
To start the stress test (Run this later once the alarm is set):
Bash
# This command stresses 2 CPUs for 600 seconds
stress --cpu 2 --timeout 600
Phase 4: Configure CloudWatch Alarm
Navigate to CloudWatch > Alarms > All alarms > Create alarm.
Click Select metric > EC2 > Per-Instance Metrics.
Search for your Instance ID and select CPUUtilization.
Conditions:
Threshold type: Static.
Whenever CPUUtilization is...: Greater than
70%.
Actions:
Select In alarm.
Send a notification to the SNS topic created in Phase 2 (
CPU_Alert_Topic).
Name the alarm:
High_CPU_Utilization_Alarm.
📊 Monitoring the Simulation
Once you execute the stress command in your terminal, watch the CloudWatch dashboard.
State: OK – CPU is below 70%.
State: In Alarm – CPU has crossed the 70% threshold. You will receive an email notification.
State: OK – Once the
stresstimeout expires, the CPU drops, and the alarm clears.
🧹 Cleanup (Avoid Unnecessary Costs)
To prevent unexpected AWS charges, ensure you delete the resources in this order:
EC2: Terminate the
Monitoring-Demo-Serverinstance.CloudWatch: Delete the
High_CPU_Utilization_Alarm.SNS: Delete the
CPU_Alert_Topicand its subscriptions.Security Groups: Remove the specific group if it’s no longer needed.
🧠 Key Learnings
Metric Intervals: Default EC2 monitoring is 5 minutes. (Detailed monitoring provides 1-minute intervals).
Alarm States: Understanding the transition from
OKtoALARMand back toOK.SNS Integration: How decoupled services communicate via Pub/Sub to keep admins informed.
#!/bin/bash
# 1. Update the system
dnf update -y
# 2. Install stress utility
# (Amazon Linux 2023 uses dnf and has stress in the default repos/epel)
dnf install stress -y
# 3. Create a log file to track progress
echo "Stress test starting at $(date)" > /var/log/stress-test.log
# 4. Execute stress command
--cpu
--timeout 600s: Run for 10 minutes (gives CloudWatch time to trigger)
stress --cpu 2 --timeout 600s >> /var/log/stress-test.log 2>&1
# 5. Log completion
echo "Stress test completed at $(date)" >> /var/log/stress-test.log