Test Knowledge On AWS

Test Knowledge On AWS

Day 47 of 90daysofdevops

ยท

6 min read

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.


Launch an EC2 instance using AMI.

  • Connect to the "apache-server" instance using the SSH client.

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

  • We have to install Apache Server using the below command

      sudo apt-get install apache2
    

  • Start the Apache service and check the status of the Apache service.

      sudo systemctl start apache2
      sudo systemctl status apache2
    
  • Change directory to /var/www/html.

  • Create a new index.html file which is a simple HTML file, as per your choice edit the index page using sudo privileges.

  • Browse public-ip which shows simple web applications.

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

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

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

    • Enable the Detailed monitoring

  • Now click on the Amazon CloudWatch dashboard.

  • In 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 "Pre-instance Metrics" but make sure you have selected the Metric Name as per your InstanceID, otherwise "Data Insufficient" error will reflect after creating metrics.

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

  • Select the metric you want to monitor, here I'm choosing 'EC2' metrics.

  • Click on 'Per-Instance Metrics'

  • Now select the metric CPU utilization credit usage

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

  • And threshold limit is 50, beyond 50 it will create an Alarm.

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

  • Click on 'Create alarm', Once the status is "OK", an alarm is created sucessfully.

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

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


Create a 'Launch Template' from the EC2 instance.

  • Initially create a 'Launch Template' from the EC2 instance.

  • Once we provide all the details click on "Create Launch Template".

    Now the Launch Template is created.

Create an Auto Scaling Group to Scale the EC2 Instance

  • Select the launch template which was created before to use for the instances in the group.

  • Choose the instance type and other configuration details such as VPC, subnet, security groups, and storage. It will be better to choose a couple of Availability Zone.

  • 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' for CPU utilization which will create a Cloud Watch Alarm.

  • Before clicking on "Create auto-scaling group" first review all the configuration that has been assigned by you.

    • Network

  • Now click on "Create Auto Scaling Group".

  • The auto-scaling group is created.

    • Once the desired capacity instance is reached, the ASG is successful.

  • Now the EC2 instances are updated as per Scaling Group desired capacity. As per load the number of instances may increase or be kept in desired capacity.

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.

    • We can verify the status of the Alarm

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

  • Click on 'By Auto Scaling Group'.

  • Choose the metric you want to monitor. You can search for the metric by name.

    • Select any metric which you want to monitor and create an alarm.

Once the alarm is created, it will start monitoring the specified metric and trigger the configured action if the conditions are met. You can view the status of the alarm in the CloudWatch console, and manage and update the alarm settings as needed.

  • We have to provide the Threshold value, so once it reaches it will create an Alarm.

  • We can provide a name for that Alarm.

  • Once you are done reviewing all the details now click on "Create Alarm". An alarm is 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.

  • SSH into the EC2 instance.

  • Install and configure the AWS CLI on your local machine.

  • Install the AWS CLI using the below command

      sudo apt update
    
      sudo apt-get install awscli
    
      aws --version
    

  • Configure AWS CLI in the server by providing AWS Access Key ID, Secret Access Key, Region Name and Output Format.

      aws configure
    

  • 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
    

  • 2 instances are running which are launched by an auto-scaling group because we choose desired capacity value as 2.

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

      aws ec2 describe-instances
    

  • Verify that the correct number of instances are running and that they are healthy and functioning properly.


Thank You,

I want to express my deepest gratitude to each and every one of you who has taken the time to read, engage, and support my journey.

Feel free to reach out to me if any corrections or add-ons are required on blogs. Your feedback is always welcome & appreciated.

~ Abhisek Moharana ๐Ÿ™‚

ย