Day 47: Test Knowledge on aws ๐Ÿ’ป ๐Ÿ“ˆ

ยท

4 min read

Task-01

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

Click on the "Launch Instance" button to start the instance creation process

Select an Amazon Machine Image (AMI) to use for the instance.

Configure the instance details such as VPC, subnet, security groups, and storage. click on 'Launch instance'

Launch instance

Click on the "Connect" button to view the connection details.

Connect to the instance using the SSH client of your choice

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

Once connected to the instance, update the package manager and install the web server (e.g. Apache, Nginx).

sudo apt-get install apache2

Start apache service and check status of apache service.

Go inside directory /var/www/html.

Create a new index.html file

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

Go to the Amazon CloudWatch dashboard.

Go to the Amazon EC2 console and select the instance you want to monitor.

Click on the "Monitoring" tab and enable "Detailed monitoring"

Go to the Amazon CloudWatch console and select the "Metrics" page.

Click on the "EC2" tab to view the available EC2 metrics.

Configure the CloudWatch alarm for the selected metric.

Click on the "Create Alarm" button to set up an alarm.

Select the metric CPU utilization

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

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

Click on 'Create alarm'

Alarm is created

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

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.

First, create a 'Launch Template' from the ec2 instance.

Launch template is created.

Click on the "Create Auto Scaling group" button to start the creation process.

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

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

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.

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

You can also create an alarm by going to the CloudWatch dashboard.

Click on the "Create Alarm" button to set up an alarm.

Click on 'By Auto Scaling Group'.

No alt text provided for this image

Click on 'By Auto Scaling Group'.

No alt text provided for this image

Once the alarm is created, it will start monitoring the specified metric and trigger the configured action if the conditions are met.

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.

Install aws cli using a command.

sudo apt-get install awsli

Configure AWS cli

Use the below command to view the state of the Auto Scaling group and the instances running in it.

aws autoscaling describe-auto-scaling-groups

There are 2 instances running which are launched by the auto-scaling group because we chose the desired capacity value is 2.

Use the below command to view the state of the EC2 instances launched by the Auto Scaling group.

aws ec2 describe-instances

Happy Learning!

ย