# Day 47 : Test Knowledge on aws 💻 📈 (Jan 12, 2024)

## **🙏 Introduction:**

In this blog, we will test the AWS knowledge of services in AWS.

## **🎯Task: 1**

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

* To begin creating an instance, click the **Launch Instance** button.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703054588043/9f39923f-1490-45d1-ae90-b40ef22c67a2.png?auto=compress,format&format=webp align="left")

* Choose an AMI from Amazon to utilize for the instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703054659848/5890ee69-1afa-499c-abf3-88a4b50e4c77.png?auto=compress,format&format=webp align="left")

* Based on your needs and requirements, select an **instance type & Key pair(login)**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703054781061/58fd9216-40b5-4703-8997-413dbb79f94a.png?auto=compress,format&format=webp align="left")

* Set up the instance's specifics, including the VPC subnet security settings and storage. the 'Launch instance' button
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703054916939/53db9bd3-f5d8-49c3-8b07-999f1f071d24.png?auto=compress,format&format=webp align="left")

* A new instance is created
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703055165965/bfb97d13-9220-40d7-ae0d-acff8d9d9af7.png?auto=compress,format&format=webp align="left")

* To view the connection information, click the **Connect** button
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703055407730/bf7542d9-e156-4339-82aa-c2b011b6255d.png?auto=compress,format&format=webp align="left")

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

* Install the web server and update the package manager once you're linked to the instance (e.g. Apache, Nginx)
    

```plaintext
sudo apt-get install apache2 -y
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703055672889/551e1f79-6385-4a8c-a977-2deadc9a1812.png?auto=compress,format&format=webp align="left")

* Launch the Apache server and verify its status
    

```plaintext
sudo systemctl start apache2
sudo systemctl status apache2
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703055846548/f0e71ae2-97ab-494d-9312-d5c7d043670c.png?auto=compress,format&format=webp align="left")

* Go inside directory /var/www/html
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703055954378/1f5eefc2-541d-483e-b67f-d49b9c52727e.png?auto=compress,format&format=webp align="left")

* Create a new index.html file which is a simple HTML file containing a simple form
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703056824611/2b0180d2-da97-4444-a72a-9ca3dafeaa59.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703056851575/16fa0440-5b2f-495d-a5ca-f88696f28cd8.png?auto=compress,format&format=webp align="left")

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

* Go to the Amazon EC2 console and select the instance you want to monitor.
    
* Click on the **Monitoring** tab and enable **Detailed monitoring**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703057182502/126a31d9-bb1f-4e11-9d65-11f140f2575a.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703057224059/08159e9b-59ac-4123-b3f4-787a8fabca55.png?auto=compress,format&format=webp align="left")

* Go to the Amazon CloudWatch console and select the **Metrics** page.
    
* Click on the **EC2** tab to view the available EC2 metrics.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703057852190/2eef0586-b7ea-45b4-a9b2-eced6000042f.png?auto=compress,format&format=webp align="left")

Select the metric you want to monitor. For example, you can monitor CPU usage, memory usage, disk I/O, or network traffic. Click on **Per-instance Metrics**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703057909436/358218a7-a35b-4c6f-9953-d8b65a4b926b.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703057966912/1a6603d0-6fa6-4e27-ab6f-730d5ba7d28a.png?auto=compress,format&format=webp align="left")

* Configure the CloudWatch alarm for the selected metric.
    
* Click on the "Create Alarm" button to set up an alarm
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058049800/7b999de9-467e-4dda-b265-25157c5c3164.png?auto=compress,format&format=webp align="left")

* Choose the condition that will trigger the alarm (e.g. when the CPU utilization is above a certain threshold for a certain amount of time).
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058333688/5b0cee08-7f29-4494-a9e7-0076d956801d.png?auto=compress,format&format=webp align="left")

* Set threshold limit is 30
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058397229/bb0c82c6-8e1e-4fd5-9e39-48811142cb39.png?auto=compress,format&format=webp align="left")

* Set up additional alarm parameters such as name, description, and notification settings.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058518815/8a0369d4-5b8f-4c17-8271-b2782c99b329.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058590616/2c35000b-86a1-4f94-b83a-8d41ebb630ea.png?auto=compress,format&format=webp align="left")

* Click on **Create Alarm,** An alarm is created
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703058706567/a4ee1691-3233-46ce-9dbd-1931a727c660.png?auto=compress,format&format=webp align="left")

* If an alarm is triggered, go to the CloudWatch dashboard to view the metrics and logs for the instance
    

## **🎯Task: 2**

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

* Create a 'Launch Template' from ec2 instance
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703082353216/cff76525-6364-46e8-a1fe-0ed7bf47179b.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703082529430/e9587eba-f5b5-4990-b2fa-9a272e3dcf0b.png?auto=compress,format&format=webp align="left")

* Launch template is created.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703082595509/9403fcd0-f6f8-4311-9f7d-d56195182749.png?auto=compress,format&format=webp align="left")

* Go to Auto Scaling group on the EC2 dashboard and click on the **Create Auto Scaling group** button.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703082787091/2f215b31-9487-48c5-b854-a8ca6f319edd.png?auto=compress,format&format=webp align="left")

* Select the launch template to use for the instances in the group
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703082904995/68342caf-8c9d-4fa6-8451-e3f448a81ecd.png?auto=compress,format&format=webp align="left")

* Choose the other configuration details such as Instance type, VPC, Availability Zones and subnets
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083163162/88e127e6-96ac-48d5-8fe9-03db3c5d6189.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083398114/d68ea1c3-d863-4119-96d0-f6ea52d0a4ad.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083420391/7aca295b-fe56-4752-9107-557b8d5d0565.png?auto=compress,format&format=webp align="left")

* Set up the scaling policies to determine when to launch new instances. configure desired, minimum and maximum capacity of instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083535248/d0a73ea6-3cce-4308-82b8-d45d236e3b29.png?auto=compress,format&format=webp align="left")

* Select **Target tracking scaling policy** and choose **metric type** to CPU utilization which will create an alarm
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083719295/8ead0df4-6240-4995-a5ae-dfd472c05ba8.png?auto=compress,format&format=webp align="left")

Select Create auto scaling group, auto scaling group is created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703083890687/994c56fb-7b25-46bd-a5f4-0739fc04914f.png?auto=compress,format&format=webp align="left")

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

* Target tracking policy in autoscaling creates 2 alarms with 2 different conditions
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703084303824/445a8b3a-6c35-47a0-a401-e136dca02b8f.png?auto=compress,format&format=webp align="left")

* 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 auto scaling group that we created, Click on the **Monitoring** tab and enable **Auto scaling group metric**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703084662164/ae7f6ac3-7889-4fda-946b-5e4a1030cca7.png?auto=compress,format&format=webp align="left")

* You can also create alarm by going to the CloudWatch dashboard, Click on the **Create Alarm** button to set up an alarm
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703084902520/64116878-0bfa-49e7-81a3-f642c32e9112.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703084982025/3c3820fc-8810-4d33-8b88-f4dc5fc907f5.png?auto=compress,format&format=webp align="left")

* Click on **Select metric**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085113269/3a170004-07d6-4dc3-8146-550c82381d10.png?auto=compress,format&format=webp align="left")

* Click on **Auto Scaling**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085226906/91f4356e-3270-41e0-8e54-79de409005ec.png?auto=compress,format&format=webp align="left")

* Click on **Group Metrics**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085301080/79cae540-adf5-4d0f-ac63-323418e137fc.png?auto=compress,format&format=webp align="left")

* Select the metric to monitor and create an alarm
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085415878/b3f208f7-3b1d-4b93-a4f5-8f5173d83bcf.png?auto=compress,format&format=webp align="left")

* Specify metric and conditions & create an alarm
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085581199/4d953886-de95-46d7-b63e-329a7761bb12.png?auto=compress,format&format=webp align="left")

* Auto Scaling alarm created
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703085662262/717918fd-921e-4f03-98f0-34ea9a61b81b.png?auto=compress,format&format=webp align="left")

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

* Install and configure the AWS CLI on your local machine
    

```plaintext
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703086341677/c0f9a7af-ce93-4de1-b629-73b44393fcfa.png?auto=compress,format&format=webp align="left")

* Configure AWS cli
    

```plaintext
aws configure
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703086690093/45096e1e-9d72-4f2b-8af6-b4377be45c57.png?auto=compress,format&format=webp align="left")

* View the state of the Auto Scaling group and the instances running
    

```plaintext
aws autoscaling describe-auto-scaling-groups
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703087179648/a2e0614e-c87f-47ce-b46c-ea7700ee8cd3.png?auto=compress,format&format=webp align="left")

* View the state of the EC2 instances launched by the Auto Scaling group**.**
    

```plaintext
aws ec2 describe-instances
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703087300993/4d10e985-2643-456c-a6cc-f06d36408fe3.png?auto=compress,format&format=webp align="left")

* Verify the number of instances is running.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703087454782/d4d4a99b-23b0-497c-be8e-8bee5f54f569.png?auto=compress,format&format=webp align="left")
