Sunday, March 20, 2022

AWS Compute - Auto Scaling & Launch Configuration


AWS Auto Scaling monitors your applications and automatically adjusts capacity to maintain steady, predictable performance at the lowest possible cost. Using AWS Auto Scaling, it's easy to setup application scaling for multiple resources across multiple services in minutes.

To Create Launch Configuration

Step 1: Create an EC2 instance Amazon Linux Image and Install apache (httpd)  and an index.html with some content.

#!/bin/bash
sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd

Connect to the Instance:

  • sudo su
  • cd /var/www/html
  • vi index.html
  • <h1> This will be auto-scale mode: scale-in and scale-out </h1>

Step 2: Create an AMI of the above EC2 instance.

go to actions --> image/templates --> create image and go through the process.


Step 3: Prepare an instance for Auto-Scaling by creating the instance via launch configuration.

Autoscaling--> Launch Configuration

Define properties of Launch Configuration

  •       Name: LC1
  •       AMI: apacheimg
  •       Instance Type: t2.micro
  •       Security Group: New Security Group and Add the HTTP Rule
  •       Key Pair : Select Existing key pair

Click on Create Launch Configuration button


To Create Autoscaling group with Launch Configuration

Step 1: Select Auto Scaling ---> Auto Scaling Group

Step 2: Click on Create Auto Scaling Group button

Step 3: Define the Auto Scaling Group properties

  •          Name:  ASG1
  •          Click on Switch To Launch Configuration.
  •          Select Launch Configuration: LC1
  •          Click on Next Button

  •          VPC : default
  •          AZs : I am selecting all.
  •          Click on Next button

  •          Load Balancing: No Load Balancer
  •          Click on Next 

  •          Desire Capacity: 3
  •          Min: 1
  •          Max: 5

  •          Select option Target Tracking Policy
  •          Metric Type Average CPU Utilization: 50
  •          Click on Next

  •          Add Notification : No Change

  •          Add Tags : No change

  •          Review and Click on Create Auto scaling group button

Step 4: Check in EC2 instances that 3 new instances are created (1 of the new instances is deleted cause the original instance is already running) as we have defined Desire Capacity = 3.

Step 5: Once you finish this lab then you can delete the Auto Scaling Group and you will observe that EC2 instances related to ASG is also deleted. (BUT the launch configuration is not deleted)


Experiments: Before Deletion

1. Check all the Ec2 instances are running with the same SG as you defined during Launch Configuration.

Answer: Yes

2. Access the default page of each EC2 instance and it should give the same output.

Answer: Yes

3. Try to delete Launch Configuration which in use.

Answer: Cannot delete because it is attached to the AutoScalingGroup

Cannot delete launch configuration Irfan-Launch-Config-for-AutoScaling because it is attached to AutoScalingGroup Irfan-AutoScalingGroup


No comments:

Post a Comment

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...