Test knowledge of AWS
Task 1:
Launch an EC2 instance using the AWS Management Console and connect to it using SSH.
- Navigate to AWS > EC2 > Lauch Instance
2. Fill the required fields:
Name: Instance name
Application and OS Images: Desired Operating System
Instance type: Desired CPU power and RAM size
Key Pair login
Enter the Key pair name, Key Pair type, and Private key file format.
Download and save the private key.
Edit the Network settings, Firewall
Select the number of instances you want to run
Click on Lauch instance.
3. Locate the downloaded PEM file, open Git Bash, and run the below command to connect the AWS EC2 instance.
ssh -i "name.pem" ubuntu@ec2-ip_address.compute-1.amazonaws.com
Here you have connected your instance
Install a web server on the EC2 instance and deploy a simple web application.
- Install the Nginix web server:
sudo apt update
sudo apt install nginx
2. Start and enable the Nginx server:
sudo systemctl start nginx
sudo systemctl enable nginx
3. Create a Simple Web Application:
sudo vim /var/www/html/index.html
Add some basic HTML content, for example:
<!DOCTYPE html>
<html>
<head>
<title>Day 47</title>
</head>
<body>
<h1>Day 47</h1>
<p>This is the solution of Day 47 task</p>
</body>
</html>
4. Access Your Web Application:
Open a web browser and enter your EC2 instance’s public IP or DNS into the address bar:
http://your-instance-ip
Monitor the EC2 instance using Amazon CloudWatch and troubleshoot any issues that arise.
- Create CloudWatch Alarms:
CloudWatch Alarms allow you to set up notifications for specific conditions or thresholds. You can create alarms for various metrics, such as CPU utilization, memory usage, disk space, and more. For example, to create a CPU utilization alarm, you can follow these steps:
- Go to the CloudWatch Management Console.
- Under “Alarms” in the left menu, click “Create Alarm.”
- Choose the metric you want to monitor (e.g., “Per-Instance Metrics” > “EC2” > “Per-Instance Metrics” > “CPUUtilization”).
- Configure the alarm condition (e.g., “Threshold type” as static, set the threshold, and the period for evaluation).
- Set up actions to perform when the alarm state is triggered, such as sending an SNS notification.
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.
Creating an Auto Scaling group in AWS and configuring it to launch EC2 instances in response to changes in demand is a crucial step for ensuring that your application can handle varying workloads. Here’s how to do it using the AWS Management Console:
1. Sign in to the AWS Management Console:
Log in to your AWS account using the [AWS Management Console]
2. Navigate to the Auto Scaling Service:
Click on “Services” in the top navigation bar, and under “Compute,” select “EC2 Auto Scaling.”
3. Create an Auto Scaling Group:
In the EC2 Auto Scaling dashboard, click on “Create Auto Scaling group.”
4. Choose Launch Template or Configuration:
You’ll be prompted to choose between creating a new launch template or using an existing one. A launch template defines the configuration of the instances that Auto Scaling will launch.
If you have a launch template, choose it, and proceed to the next step.
— If not, you can create a new one by clicking “Create launch template” and configuring it with your desired instance settings.
5. Configure Auto Scaling Group Details:
In this step, you’ll configure the Auto Scaling group details:
- Group name: Give your Auto Scaling group a name.
-Network: Select the VPC and subnet(s) in which your instances will be launched.
-Launch template: Choose the launch template you created or selected in the previous step.
-Instance types: Specify the instance types you want to use.
-Purchase options: Choose the purchase options for your instances (On-Demand, Spot Instances, or a mix).
-Minimum/Desired/Maximum capacity: Set the minimum, desired, and maximum number of instances in the group.
-Network settings: Configure security groups, key pair, and IAM role.
-Load balancing: If you have an Application Load Balancer, Network Load Balancer, or Classic Load Balancer, you can associate it with your Auto Scaling group.
-Health checks: Configure health checks for instances to determine if they are healthy.
6. Configure Scaling Policies:
In the “Configure scaling policies” section, you set up the rules that dictate how your group scales based on demand:
- Target tracking scaling: Choose a metric (e.g., CPU utilization, network in/out, etc.), set a target value, and specify a scaling adjustment.
-Step scaling: Define step adjustments based on a metric and the scaling adjustment.
7. Configure Notifications:
You can set up notifications to be alerted when Auto Scaling events occur, like instances being launched or terminated.
8. Review and Create:
Review your Auto Scaling group configuration and click “Create Auto Scaling group.
Your Auto Scaling group is now created, and it will automatically adjust the number of instances in response to changes in demand based on the scaling policies you’ve defined.
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.
- View the State of the Auto Scaling Group
aws autoscaling describe-auto-scaling-groups