Host Website and Monitor Using CloudWatch

Host Website and Monitor Using CloudWatch

  • Launch an EC2 instance using the AWS Management Console and connect to it using SSH.

  • Install a web server on the EC2 instance and deploy a simple web application.

  • Monitor the EC2 instance using Amazon CloudWatch and troubleshoot any issues that arise.

Launch the EC2 Instance using the template

Has AMI-Ubuntu, tr.micro, Networking-Default, Keypair-Usable, and User Data as follows. After this configuration Click on Create Template.

#!/bin/bash
sudo apt update -y
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
sudo rm /var/www/html/index.html
sudo touch /var/www/html/index.html
sudo chmod 777 /var/www/html/index.html
echo "<header> <h1> Welcome to <a href="https://kshitijaa.hashnode.dev/" target="_blank"> Kshitija-Bartakke-Malwade-Blogs!</h1> </header>" > var/www/html/index.html
sudo systemctl restart apache2

Launch Instance from this template, Select Template --> Actions --> Launch Instance From Template

Review and Launch Instance!

I can browse my application without even logging to instance! This is the power of User Data! (Automation)

Now let's configure the CloudWatch Alert if the CPU utilization is more than 80%

Go to EC2 Instance dashboard, select your instance -> Actions -> Drop down and select -> Monitor and troubleshoot -> Manage CloudWatch alarms

Add CloudWatch Alarm -> Create Alarm and select already created SNS topic

Add threshold levels -> Type: CPU Utilization, Alarm when: > , Perscent 80

After the configuration, you can see below the matric curves, Click on Create

Now, since my website utilizing more than 80% CPU. The alarm status is in red

I have received the alarm via Email, through the SNS topic! (For more info on SNS kindly visit my previous blog: click here )

If you zoom in below image and see properly, we have received alarm with exact timestamp and details.

This is the clear detailed view of the CloudWatch alarm to troubleshoot.

This is how you can monitor your website using CloudWatch!

Good Catch - You must be thinking why my website is reaching more than 90% CPU utilization? Who will be accessing it? The answer is simple 'STRESS', you can install sudo apt install stress -y and run command sudo stress --cpu 8 -v --timeout 30sYour EC2 CPU utilization will reach to the max to get the alert notification.

Thanks for spending your valuable time in learning to enhance your career!๐Ÿ˜ƒ๐Ÿ™

ย