Day 47: Test Knowledge on AWS
We’ve been learning AWS from past week and we’ve learnt many services. Today, we will be testing the AWS knowledge on services in AWS, as part of the 90 Days of DevOps Challenge.
Tasks -
Task 1) A)Launch an EC2 instance using the AWS Management Console and connect to it using SSH.
Open AWS console > ec2 > Launch instances
our ec2 instance is launched. Click on connect
Copy the below command and run this command in the terminal where your keypair is present.
ssh -i “mykeypair1.pem” ubuntu@ec2–52–53–178–32.us-west-1.compute.amazonaws.com
Here, We’ve successfully connected our ec2 instance through SSH
B) Install a web server on the EC2 instance and deploy a simple web application.
Update the instance with the latest packages and security patches, using
sudo apt-get update -y
Let us install an Apache web server, using:
sudo apt-get install apache2 -y
Let us start this service using:
sudo systemctl start apache2
sudo systemctl status apache2
Let us try connecting to this Web server using the Public IPv4 of the instance.
Here our IPV4 is “52.53.178.32"
Here we can connect to server successfully!
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
Replace the contents of the index.html file with:
<!DOCTYPE html>
<html>
<head>
<title>Day 47/90: 90DaysOfDevOps Challenge</title>
<style>
body {
background-color: #f2f2f2; /* Set your desired background color */
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h1 {
color: #333; /* Set your desired text color */
padding: 20px;
background-color: #fff;
border-bottom: 1px solid #ccc;
}
h2 {
color: #666; /* Set your desired text color */
padding: 10px;
background-color: #fff;
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<h1>Day 47/90 - 90DaysOfDevOps Challenge </h1>
<h2>My Name Is Radheya Zunjur</h2>
</body>
</html>
Yay!!! We have installed web server and deployed a web application on our ec2 instance.
C) Monitor the EC2 instance using Amazon CloudWatch and troubleshoot any issues that arise.
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.
In your EC2 Console > Select the Instance you want to monitor > Go to the Monitoring Tab > Click on Manage Detailed Monitoring
Enable the Detailed Monitoring in the pop-up and click on Confirm.
Task 2)
Step A) Create an Auto Scaling group using the AWS Management Console and configure it to launch EC2 instances in response to changes in demand.
Go to EC2 Console > Select the EC2 Instance > Actions > Image and templates > Create a template from the instance.
Let the Launch template name be my-template > Template version description be “Template test launch template” > Click on Create launch template
You can verify the template created when it appears in the dashboard:
Go to your EC2 console > Under Auto Scaling > Select Auto Scaling Groups > Create Auto Scaling Groups >
Auto Scaling group name: My-ASG
Launch template: Select the launch template you created
Click on Next.
In the next section > Select a couple of availability zones > Click on Next > Enable Monitoring > Click on Next
Set the Group size as per your requirement:
Review and Create the AutoScaling Group
let’s create alarms
Step B) 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 to your instance and install the AWS CLI using:
sudo apt update
sudo apt-get install awscli
aws --version
Configure your AWS CLI with Access Key ID and Secret Access Key.
aws configure
Let us see the ASGs by using the:
aws autoscaling describe-auto-scaling-groups
Let us verify the ec2 instances:
aws ec2 describe-instances
By running this command below, you can check the instances that are there:
aws ec2 describe-instances | grep -w "KeyName"
We can verify that there are 3 Instances from the EC2 console: