Back
6
☁️ Practical 6: Monitor Resources Using AWS CloudWatch
Objective: Use AWS CloudWatch to monitor AWS resources properly and set up triggered SNS Alarms.
🖥️ Method 1: Console / GUI Guide (AWS Management Console)
If you prefer to provision infrastructure manually via the Management Console, follow these steps:
- Log In: Open the CloudWatch Dashboard in the AWS Console.
- Find Metrics: Click All metrics and search correctly for AWS/EC2.
- Select Instance: Select an existing running EC2 instance and find the specific CPUUtilization metric.
- Create Alarm: Go to Alarms > Create alarm and systematically select the metric you just chose.
- Set Threshold: Set the condition to reliably trigger Greater than 80%.
- Configure SNS: In the Notification step, select Create new topic (SNS). Enter an email address you have access to.
- Confirm Email: You will need to click the direct confirmation link sent to your email to permanently activate the subscription.
🚀 Method 2: Automated Script Guide
For rapid, reproducible deployments, use the provided bash scripts.
🔍 Script Analysis
| Script Name | Action Performed |
|---|---|
6monitordeploy.sh |
🟢 Deploys an EC2 instance and structurally sets up SNS (Simple Notification Service) topics. It attaches a CloudWatch Alarm explicitly configured to trigger an alert if CPU utilization spikes above a predefined threshold. |
6monitorcleanup.sh |
🔴 Deletes the CloudWatch alarms, firmly un-subscribes users, smoothly deletes the SNS topic, and forcibly terminates the monitored EC2 instance. |
🛠️ Usage Instructions
Prerequisites:
- AWS CLI installed and configured with active credentials.
Execute the following commands from the root directory:
# 1. Navigate to scripts folder
cd scripts/
# 2. Provide execution permission
chmod +x 6_monitor_deploy.sh 6_monitor_cleanup.sh
# 3. Deploy EC2, SNS Topic, and CloudWatch Alarms
./6_monitor_deploy.sh
# 4. Clean up alarms, topics, and compute instance
./6_monitor_cleanup.sh
🖼️ Result / Output
CloudWatch Dashboard
Figure 6.1: Custom CloudWatch Dashboard showing CPU and Network metrics.
Monitored Instances
Figure 6.2: EC2 instances listed in the CloudWatch monitoring context.
SNS Topic Setup
Figure 6.3: Successful creation of the SNS notification topic.
SNS Subscriptions
Figure 6.4: Active email subscription for monitoring alerts.