Day 47 - Test Knowledge on AWS

Day 47 - Test Knowledge on AWS

Table of contents

TASK 1

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

Let's start with the steps👇

Step 1: Login to AWS Console and on search bar type "EC2".

Step 2: Launch an instance with the below details.

  1. Name: Web-Server

  2. Number of instances: 1

  3. Application and OS Images (Amazon Machine Image): Ubuntu AMI

  4. Instance type: t2.micro

  5. Key pair (login): Select the key pair you want or create a new one.

  6. Network Settings: Check the boxes “Allow HTTPS traffic from the Internet” & “Allow HTTP traffic from the Internet”

Step 3: Click on Launch Instance.

Step 4: Select the instance and Click on Connect.

Step 5: Let’s connect to the EC2 instance using SSH.

Step 6: Update the instance with the latest packages and security patches, using the below command.

sudo apt-get update -y

Step 7: Let's install an Apache web server, using the below command.

sudo apt-get install apache2 -y

Step 8: Let us start this service using:

sudo systemctl start apache2
sudo systemctl status apache2

Step 9: Let us try connecting to this Web server using the Public IPv4 of the instance.

Step 10: Let us deploy a sample application on this server. Go to the /var/www/html directory where the index.html file is present.

cd /var/www/html
ls

Step 11: Replace the contents of the index.html file with the below content.

<!DOCTYPE html>
<html>
<head>
<title>New Application - Apache</title>
</head>
<body>
<h1>Hello, world! This is my sample application</h1>
<h2>I am a DevOps Enthusiast</h2>
</body>
</html>

Step 12: Restart the web server using the below command.

sudo systemctl restart apache2

Step 13: And using the Public IPv4 of the Instance, you can verify that you have successfully deployed.

Step 14: To use the CloudWatch service, you should enable a few important things in the Billing preferences. Here’s the link on how to do the same: CloudWatch.

Step 15: In your EC2 Console > Select the Instance you want to monitor > Go to the Actions > Monitor and troubleshoot Tab > Click on Manage Detailed Monitoring.

Step 16: Enable the Detailed Monitoring in the pop-up and click on Confirm.

Step 17: Once done, Navigate to CloudWatch > Metrics > All Metrics > Select EC2

Step 18: Click on Per-Instance Metrics > And select the Metrics you want to monitor > Select CPU Utilization.

Step 19: Now let us create the Alarm. Go to Alarms > All Alarms > Create Alarm > Select Metric > Select EC2 > Select Per Instance Metrics > Select the CPU Utilization > Click on Select Metric

Step 20: Click on Next.

Step 21: In Configure actions, Under Notifications: For the Alarm state trigger select In alarm > Create New Topic > Create a topic with your mail ID and topic name.

Step 22: Click on Next.

Step 23: In Add name and description, For the Alarm name give WebServerAlarm > Click on Next.

Step 24: Preview and create.
Preview the Alarm you have created and click on Create Alarm.

Step 25: Confirm the subscription from your given email to receive the Amazon SNS.

Step 26: So when you go beyond the threshold, you will receive an alarm.

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.

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

Let's start with the steps👇

Step 1: Let us Create a Launch Template from our existing EC2 instance. Go to EC2 Console > Select the EC2 Instance > Actions > Image and templates > Create a template from the instance.

Step 2: Let the Launch template name be new-test-template > Template version description be “Template test launch template” > Click on Create launch template

Step 3: You can verify the template created when it appears in the dashboard:

Step 4: Go to your EC2 console > Under Auto Scaling > Select Auto Scaling Groups > Create Auto Scaling Groups

  1. Auto Scaling group name: test-ASG

  2. Launch template: Select the launch template you created

Step 5: Click on Next.

Step 6: In the next section > Select a couple of availability zones > Click on Next > Enable Monitoring > Click on Next

Step 7: Set the Group size as per your requirement:

Step 8: Select Target Tracking Policy > Click on Next

Step 9: Preview and Create the ASG.

Step 10: In the EC2 Instances dashboard, you can see that the number of instances is increased to three (as per your requirement).

Step 11: You can see that the Target tracking policy has created two more alarms:

Step 12: Go to the ASG we created > Enable ASG Metric.

Step 13: Let us create an Alarm for the same ASG.

Step 14: SSH to your instance and install the AWS CLI using:

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

Step 15: Configure your AWS CLI with Access Key ID and Secret Access Key.

aws configure

Step 16: Let us see the ASGs by using the:

aws autoscaling describe-auto-scaling-groups

Step 17: Let us verify the ec2 instances:

aws ec2 describe-instances

Step 18: By running this command below, you can check the instances that are there:

aws ec2 describe-instances | grep -w "KeyName"

Step 19: We can verify that there are 3 Instances from the EC2 console.

Conclusion

In this blog, I have tested my knowledge of AWS services which I have used previously in the challenge.

Hope you find it helpful🤞 So I encourage you to try this on your own and let me know in the comment section👇 about your learning experience.✨

*👆The information presented above is based on my interpretation. Suggestions are always welcome.*😊

~Smriti Sharma✌