Table of contents
π 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.
- Choose an AMI from Amazon to utilize for the instance.
- Based on your needs and requirements, select an instance type & Key pair(login)
- Set up the instance's specifics, including the VPC subnet security settings and storage. the 'Launch instance' button
- A new instance is created
- To view the connection information, click the Connect button
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)
sudo apt-get install apache2 -y
- Launch the Apache server and verify its status
sudo systemctl start apache2
sudo systemctl status apache2
- Go inside directory /var/www/html
- Create a new index.html file which is a simple HTML file containing a simple form
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
Go to the Amazon CloudWatch console and select the Metrics page.
Click on the EC2 tab to view the available EC2 metrics.
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
Configure the CloudWatch alarm for the selected metric.
Click on the "Create Alarm" button to set up an alarm
- 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 threshold limit is 30
- Set up additional alarm parameters such as name, description, and notification settings.
- Click on Create Alarm, An alarm is created
- 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
- Launch template is created.
- Go to Auto Scaling group on the EC2 dashboard and click on the Create Auto Scaling group button.
- Select the launch template to use for the instances in the group
- Choose the other configuration details such as Instance type, VPC, Availability Zones and subnets
- 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
Select Create auto scaling group, auto scaling group is created.
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 auto scaling group that we created, Click on the Monitoring tab and enable Auto scaling group metric
- You can also create alarm by going to the CloudWatch dashboard, Click on the Create Alarm button to set up an alarm
- Click on Select metric
- Click on Auto Scaling
- Click on Group Metrics
- Select the metric to monitor and create an alarm
- Specify metric and conditions & create an alarm
- Auto Scaling alarm created
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
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
- Configure AWS cli
aws configure
- View the state of the Auto Scaling group and the instances running
aws autoscaling describe-auto-scaling-groups
- View the state of the EC2 instances launched by the Auto Scaling group.
aws ec2 describe-instances
- Verify the number of instances is running.
π Conclusion :
In this blog, we demonstrate a few tasks related to the Auto Scaling group CloudWatch & AWS CLI, in the next blog, we will cover AWS Topics.
Thank you for reading!
Contact me on Linkedin
Check out my GitHub for more resources π