Day 47 - Test Knowledge on AWS (Cloud Watch)

Day 47 - Test Knowledge on AWS (Cloud Watch)

Task-01

  • 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.

Launching an Ec2 instance and connecting through SSH

The Ubuntu instance is ready and running. Click on Connect and copy the SSH command

Now open the terminal in the directory, where you have saved your pem key and paste the ssh command

Install Webserver and Deploy a simple web application on EC2

Execute the below commands on the EC2 terminal

$ sudo apt-get update 
$ sudo apt-get install apache2 -y

You can edit the index.html file of apache2 if you want to make any changes

$ cd /var/www/html
$ sudo nano index.html

In my case, I am not making any edits and directly accessing the apache2

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

  1. Select the Ec2 instance that you want to monitor

  2. Click Actions > Monitor and troubleshoot> Manage detailed monitoring > Confirm

  1. Navigate to CloudWatch > Alarm > All Alarms > Create Alarm > Select metric

  2. Select metric as EC2 > Perinstance Metrics

  1. Copy your instance ID and paste it into the search bar

Now search for the metric that you want to create an alarm, in our case CPU Utilization and click on Select metric

Click on Next

Click on Create alarm


TASK - 02

  • Create an Auto Scaling group using the AWS Management Console and configure it to launch EC2 instances in response to changes in demand.

  • Use Amazon CloudWatch to monitor the performance of the Auto Scaling group and the EC2 instances and troubleshoot any issues that arise.

  • Use the AWS CLI to view the state of the Auto Scaling group and the EC2 instances and verify that the correct number of instances are running.

Launching a Template

  1. Select the instance from where we want to launch the template

  2. Actions > Image and templates > Create template from instance

Everything is taken from the previous source instance, so give it a name and click on Create launch template.

Creating an Autoscaling Group

  1. EC2 > Auto Scaling groups > Create Auto Scaling group

Review all and click on Create Autoscaling group

Instantly 2 instances will be created by the Autoscaling group

Use Amazon CloudWatch to monitor the performance of the Auto Scaling group and the EC2 instances and troubleshoot any issues that arise.

While creating an Autoscaling Group, we used a Target tracking policy for Metric Type CPU Utilization. So it creates two 2 alarms in Cloud Watch.

Once the alarm is set up, it will start monitoring the specified metric for the Auto Scaling group. If the metric exceeds the threshold that you have set, the alarm will be triggered and take the action that you have specified.

Go to the auto-scaling group that we created, Click on the "Monitoring" tab and enable "Auto scaling group metric"

Create a CloudWatch for Autoscaling Group

Cloudwatch > Alarm > Create Alarm > EC2 > By Autoscaling group

Follow the steps to complete the alarm and activate it.

Use the AWS CLI to view the state of the Auto Scaling group and the EC2 instances and verify that the correct number of instances are running.

  1. Connect to the Source Ec2 Instance

  1. Install aws cli
$ sudo apt-get update
$ sudo apt install awscli -y
  1. Aws configure

# Gives us the information about autoscalinggroups
$ aws autoscaling describe-auto-scaling-groups

# Gives us th info about the instances
$ aws ec2 describe-instances