<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Cloud Guardian: Real-Time EC2 Monitor]]></title><description><![CDATA[Cloud Guardian: Real-Time EC2 Monitor]]></description><link>https://cloudguardian.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 09:41:56 GMT</lastBuildDate><atom:link href="https://cloudguardian.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Cloud Guardian: Building a Robust AWS Monitoring Solution with EC2, CloudWatch, and SNS]]></title><description><![CDATA[Monitoring cloud infrastructure is critical for performance, cost optimization, and security. Cloud Guardian is an open-source project that showcases how…]]></description><link>https://cloudguardian.hashnode.dev/cloud-guardian-building-a-robust-aws-monitoring-solution-with-ec2-cloudwatch-and-sns</link><guid isPermaLink="true">https://cloudguardian.hashnode.dev/cloud-guardian-building-a-robust-aws-monitoring-solution-with-ec2-cloudwatch-and-sns</guid><category><![CDATA[Cloud]]></category><category><![CDATA[#CloudWatch]]></category><category><![CDATA[Terraform]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Amit Kushwaha ]]></dc:creator><pubDate>Wed, 28 May 2025 17:14:42 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748535197353/aa9d0612-86e3-47ac-bd92-64f0bfc9d040.png" alt class="image--center mx-auto" /></p>
<p>Monitoring cloud infrastructure is critical for performance, cost optimization, and security. <strong>Cloud Guardian</strong> is an open-source project that showcases how to use AWS EC2, CloudWatch, and SNS to monitor CPU utilization and send real-time alerts. This blog walks you through the project’s implementation, complete with interactive code snippets, a CPU utilization chart, and ways to engage with the project. Whether you’re a DevOps engineer, cloud enthusiast, or developer, Cloud Guardian offers a practical blueprint for AWS monitoring.</p>
<p>Explore the project on GitHub: <a target="_blank" href="https://github.com/amitkumar-Github8/Cloud-Guardian">Cloud Guardian</a></p>
<h2 id="heading-project-overview">Project Overview</h2>
<p>Cloud Guardian is an open-source project designed to monitor AWS EC2 instance performance, specifically CPU utilization, and send instant notifications via AWS SNS when thresholds are breached. By using Terraform for infrastructure provisioning and a Python script for testing, the project showcases a practical approach to cloud resource management. The core components include:</p>
<ul>
<li><p><strong>AWS EC2</strong>: A t2.micro instance for running workloads.</p>
</li>
<li><p><strong>AWS CloudWatch</strong>: Real-time monitoring of CPU utilization with customizable alarms.</p>
</li>
<li><p><strong>AWS SNS</strong>: Email notifications triggered when CPU usage exceeds 50%.</p>
</li>
<li><p><strong>Terraform</strong>: Infrastructure-as-code for automated EC2 setup.</p>
</li>
<li><p><strong>Python Testing Script</strong>: A <code>cpu_spike.py</code> script to simulate CPU load and validate alerts.</p>
</li>
</ul>
<p>The project is hosted on GitHub at <a target="_blank" href="https://github.com/amitkumar-Github8/Cloud-Guardian">Cloud Guardian</a>, though the repository. Let’s explore how Cloud Guardian was built and how you can replicate it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534555016/ce8dc877-f90a-47c3-a8ab-74fb821d5cbf.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: The Cloud Guardian dashboard displaying real-time CPU utilization metrics.</p>
<h2 id="heading-why-cloud-guardian">Why Cloud Guardian?</h2>
<p>Monitoring cloud resources is critical for maintaining performance, optimizing costs, and ensuring security. Cloud Guardian addresses these needs by:</p>
<ul>
<li><p>Automating EC2 instance provisioning with Terraform.</p>
</li>
<li><p>Providing real-time insights into CPU utilization via CloudWatch.</p>
</li>
<li><p>Delivering instant alerts through SNS for proactive incident response.</p>
</li>
<li><p>Enabling stress testing with a Python script to verify monitoring accuracy.</p>
</li>
</ul>
<p>This project is ideal for developers learning AWS, DevOps practitioners implementing monitoring solutions, or businesses aiming to enhance cloud infrastructure reliability.</p>
<h2 id="heading-implementation-journey">Implementation Journey</h2>
<h3 id="heading-1-setting-up-the-ec2-instance">1. Setting Up the EC2 Instance</h3>
<p>The foundation of Cloud Guardian is an AWS EC2 t2.micro instance, provisioned using Terraform. The setup includes:</p>
<ul>
<li><p><strong>Instance Creation</strong>: Launched a t2.micro instance, a cost-effective choice for testing.</p>
</li>
<li><p><strong>Security Groups</strong>: Configured to allow SSH access for secure management.</p>
</li>
<li><p><strong>Detailed Monitoring</strong>: Enabled CloudWatch detailed monitoring for granular metrics.</p>
</li>
</ul>
<p>The Terraform configuration files (<code>main.tf</code>, <code>variables.tf</code>, <code>provider.tf</code>, and <code>terraform.tfvars</code>) define the infrastructure, ensuring reproducibility and scalability.</p>
<pre><code class="lang-bash">resource <span class="hljs-string">"aws_instance"</span> <span class="hljs-string">"instance_log"</span> {
  ami           = var.ami_id
  instance_type = var.instance_type
  key_name      = var.key_name

  <span class="hljs-comment"># Security group for SSH access</span>
  vpc_security_group_ids = [aws_security_group.ssh_sg.id]

  tags = {
    Name        = <span class="hljs-string">"cloud-guardian-instance"</span>
    Project     = <span class="hljs-string">"Cloud Guardian"</span>
  }
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534597963/c9d7c775-9180-4023-8d16-cd4eb6968362.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: Screenshot of the AWS EC2 console showing the configured t2.micro instance.</p>
<h3 id="heading-2-integrating-cloudwatch-for-monitoring">2. Integrating CloudWatch for Monitoring</h3>
<p>AWS CloudWatch is the backbone of Cloud Guardian’s monitoring capabilities. Key steps included:</p>
<ul>
<li><p><strong>Metrics Collection</strong>: Configured CloudWatch to track CPU utilization in real time.</p>
</li>
<li><p><strong>Alarm Setup</strong>: Created an alarm to trigger when CPU usage exceeds 50%.</p>
</li>
<li><p><strong>SNS Integration</strong>: Linked the alarm to an SNS topic for email notifications.</p>
</li>
</ul>
<p>This setup ensures that any performance anomalies are detected and communicated instantly.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534697276/be059c4b-2137-4ab5-a975-bdb6cfb2d9fe.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: CloudWatch dashboard displaying CPU utilization metrics and alarm status.</p>
<h3 id="heading-3-configuring-sns-notifications">3. Configuring SNS Notifications</h3>
<p>AWS SNS (Simple Notification Service) enables real-time email alerts. The process involved:</p>
<ul>
<li><p>Creating an SNS topic in the AWS Console.</p>
</li>
<li><p>Subscribing an email address to the topic and confirming the subscription.</p>
</li>
<li><p>Linking CloudWatch alarms to the SNS topic to trigger notifications when CPU usage exceeds the 50% threshold.</p>
</li>
</ul>
<p>This ensures stakeholders are promptly informed of potential issues, enabling quick resolution.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534742197/552eec0e-686c-418c-8e58-41a8982b4042.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: AWS SNS console showing the configured topic and email subscription.</p>
<h3 id="heading-4-testing-and-validation">4. Testing and Validation</h3>
<p>To verify the monitoring system, Cloud Guardian includes a Python script (<code>cpu_spike.py</code>) to simulate CPU load. The testing process was:</p>
<ul>
<li><p><strong>Initial Check</strong>: Confirmed CloudWatch was collecting metrics under normal conditions.</p>
</li>
<li><p><strong>CPU Spike Test</strong>: Ran <code>cpu_spike.py</code> to generate a CPU load (e.g., 80% for 30 seconds).</p>
</li>
<li><p><strong>Validation</strong>: Verified that CloudWatch detected the spike, triggered the alarm, and sent an SNS notification.</p>
</li>
</ul>
<p>The script supports customizable parameters:</p>
<pre><code class="lang-bash">python cpu_spike.py --duration 60 --cpu-percent 80
</code></pre>
<p>This command simulates a 80% CPU load for 60 seconds, ideal for testing high-load scenarios.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534782653/317f1fec-df36-4212-a4a9-5b37993c6f04.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: Graph showing CPU utilization spike during testing, with the alarm triggered.</p>
<h2 id="heading-project-structure">Project Structure</h2>
<p>The Cloud Guardian repository is organized for clarity and ease of use:</p>
<pre><code class="lang-bash">Cloud-Guardian/
├── EC2/
│   ├── main.tf            <span class="hljs-comment"># Terraform configuration for EC2</span>
│   ├── variables.tf       <span class="hljs-comment"># Variable definitions</span>
│   ├── terraform.tfvars   <span class="hljs-comment"># Variable values</span>
│   ├── provider.tf        <span class="hljs-comment"># AWS provider settings</span>
│   ├── README.md          <span class="hljs-comment"># EC2-specific documentation</span>
├── default_metrics_demo/
│   └── cpu_spike.py       <span class="hljs-comment"># Python script for CPU load testing</span>
└── README.md              <span class="hljs-comment"># Project overview</span>
</code></pre>
<p>This structure separates infrastructure code from testing scripts, making it easy to manage and extend.</p>
<h2 id="heading-key-features">Key Features</h2>
<ul>
<li><p><strong>Automated Provisioning</strong>: Terraform scripts streamline EC2 setup.</p>
</li>
<li><p><strong>Real-Time Monitoring</strong>: CloudWatch tracks CPU utilization, memory, disk, and network metrics.</p>
</li>
<li><p><strong>Instant Alerts</strong>: SNS delivers email notifications for CPU spikes.</p>
</li>
<li><p><strong>Secure Access</strong>: SSH-enabled with security group configurations.</p>
</li>
<li><p><strong>Testing Framework</strong>: <code>cpu_spike.py</code> validates monitoring and alerting reliability.</p>
</li>
</ul>
<h2 id="heading-how-to-get-started">How to Get Started</h2>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p><strong>Tools</strong>: Terraform (v1.0.0+), AWS CLI, Git.</p>
</li>
<li><p><strong>AWS Requirements</strong>: Active AWS account, IAM permissions, access keys, verified email for SNS.</p>
</li>
</ul>
<h3 id="heading-setup-guide">Setup Guide</h3>
<ol>
<li><p><strong>Clone the Repository</strong>:</p>
<pre><code class="lang-bash"> git <span class="hljs-built_in">clone</span> https://github.com/amitkumar-Github8/Cloud-Guardian.git
 <span class="hljs-built_in">cd</span> Cloud-Guardian
</code></pre>
</li>
<li><p><strong>Configure AWS CLI</strong>:</p>
<pre><code class="lang-bash"> aws configure
</code></pre>
<p> Enter your AWS Access Key ID, Secret Access Key, region, and output format (e.g., JSON).</p>
</li>
<li><p><strong>Set Up SNS</strong>:</p>
<ul>
<li><p>Navigate to the <a target="_blank" href="https://aws.amazon.com/sns/">AWS SNS Console</a>.</p>
</li>
<li><p>Create a new topic and subscribe your email.</p>
</li>
<li><p>Confirm the subscription via the email received.</p>
</li>
</ul>
</li>
<li><p><strong>Deploy Infrastructure</strong>:</p>
<pre><code class="lang-bash"> <span class="hljs-built_in">cd</span> EC2
 terraform init
 terraform plan
 terraform apply
</code></pre>
</li>
<li><p><strong>Run CPU Spike Test</strong>:</p>
<pre><code class="lang-bash"> <span class="hljs-built_in">cd</span> default_metrics_demo
 python cpu_spike.py --duration 30 --cpu-percent 80
</code></pre>
</li>
</ol>
<p><strong>[Insert Image Here: Terraform Apply Output]</strong><br /><em>Caption</em>: Terminal output of <code>terraform apply</code> showing successful EC2 deployment.</p>
<h2 id="heading-monitoring-results">Monitoring Results</h2>
<p>The project successfully demonstrated:</p>
<ul>
<li><p><strong>CPU Tracking</strong>: CloudWatch captured real-time CPU utilization.</p>
</li>
<li><p><strong>Alert Triggering</strong>: Alarms activated at 50% CPU usage.</p>
</li>
<li><p><strong>Notification Delivery</strong>: SNS emails were sent promptly.</p>
</li>
<li><p><strong>Real-Time Validation</strong>: Metrics and alerts functioned as expected.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748534839485/1eeab5e0-5ff1-4860-b324-20876dacc4ff.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748535069093/ac75bedb-b53d-4d7e-bfa6-61c7eb7f6f14.png" alt class="image--center mx-auto" /></p>
<p><em>Caption</em>: CloudWatch alarm state transitioning to "ALARM" during a CPU spike.</p>
<h2 id="heading-technologies-used">Technologies Used</h2>
<ul>
<li><p><strong>AWS EC2</strong>: <a target="_blank" href="https://aws.amazon.com/ec2/">aws.amazon.com/ec2</a></p>
</li>
<li><p><strong>AWS CloudWatch</strong>: <a target="_blank" href="https://aws.amazon.com/cloudwatch/">aws.amazon.com/cloudwatch</a></p>
</li>
<li><p><strong>AWS SNS</strong>: <a target="_blank" href="https://aws.amazon.com/sns/">aws.amazon.com/sns</a></p>
</li>
<li><p><strong>Terraform</strong>: <a target="_blank" href="https://www.terraform.io/">terraform.io</a></p>
</li>
<li><p><strong>Python</strong>: For the <code>cpu_spike.py</code> testing script.</p>
</li>
</ul>
<h2 id="heading-why-this-matters">Why This Matters</h2>
<p>Cloud Guardian is more than a proof-of-concept; it’s a practical blueprint for monitoring cloud infrastructure. By automating provisioning, monitoring, and alerting, it reduces manual overhead and ensures rapid response to performance issues. This project is particularly valuable for:</p>
<ul>
<li><p><strong>Learning AWS</strong>: Understand EC2, CloudWatch, and SNS in a real-world context.</p>
</li>
<li><p><strong>DevOps Practices</strong>: Implement infrastructure-as-code and automated monitoring.</p>
</li>
<li><p><strong>Cost Optimization</strong>: Identify and address resource overuse early.</p>
</li>
</ul>
<h2 id="heading-future-enhancements">Future Enhancements</h2>
<p>To extend Cloud Guardian, consider:</p>
<ul>
<li><p>Adding more metrics (e.g., memory, disk space) to CloudWatch.</p>
</li>
<li><p>Supporting additional notification channels (e.g., SMS, Slack).</p>
</li>
<li><p>Integrating with AWS Security Hub for enhanced security monitoring.</p>
</li>
<li><p>Automating multi-instance monitoring for larger deployments.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Cloud Guardian showcases the power of AWS services in building a robust monitoring solution. By combining EC2, CloudWatch, SNS, and Terraform, it provides a scalable, automated approach to cloud resource management. Whether you’re a beginner exploring AWS or a seasoned engineer optimizing infrastructure, this project offers valuable insights and a replicable framework.</p>
<p>Explore the project on GitHub: <a target="_blank" href="https://github.com/amitkumar-Github8/Cloud-Guardian">amitkumar-Github8/Cloud-Guardian</a>. Star the repository if you find it useful, and feel free to contribute or open issues for support!</p>
<p><strong>[Insert Image Here: Cloud Guardian Architecture Diagram]</strong><br /><em>Caption</em>: Diagram illustrating the flow from EC2 to CloudWatch to SNS notifications.</p>
<hr />
<p><em>About the Author</em>: Amit Kumar is a cloud enthusiast and developer passionate about AWS and infrastructure automation. Follow my work on <a target="_blank" href="https://github.com/amitkumar-Github8">GitHub</a> or connect on <a target="_blank" href="https://hashnode.com/">Hashnode</a> for more cloud projects and tutorials.</p>
<p><em>Resources</em>:</p>
<ul>
<li><p><a target="_blank" href="https://docs.aws.amazon.com/">AWS Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://www.terraform.io/docs">Terraform Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/amitkumar-Github8/Cloud-Guardian">Contribute to Cloud Guardian</a></p>
</li>
</ul>
]]></content:encoded></item></channel></rss>