CREATING AN AUTOSCALING GROUP

Tobi
4 min readOct 23, 2022

--

Creating VPC, 3 Public Subnet, a Route Table and an Internet Gateway

From the console, go to the VPC, select VPC and more, this would let us create the VPC, 3 public subnet, a route table and an internet gateway all at once instead of creating them one at a time.

A preview of what we’re trying to create looks like this

We have a VPC, 3 Public Subnet, a Route Table and an Internet Gateway created.

Create Security Group

You’ll find security group under VPC and you can also find security group under EC2, go for whichever is easier, it doesn’t matter where you set it up. You’ll set your inbound rule to allow SSH from your IP address and allow HTTP from anywhere.

Create Launch Template

Navigate to Ec2 on the console, Under “instance”, go to “Launch template”, then click on Create Launch Template. You can configure your Launch Template just as I have done mine in the images below. Remember to create a new key pair if you don’t have on already, Make sure you enable auto-assign public Ip under the Network settings. Also make sure you leave everything as it is in the advance settings and just use the same script in your user data. After doing all this, click on “Create Launch Template”

Create Auto Scaling Group

Navigate to Ec2 on the console, Under “Auto Scaling”, go to “Auto Scaling Groups”, then click on “create Auto Scaling Group”. Give your Auto Scaling Group a name and attach your launch template, under Network, choose your vpc and the availability zone of the subnets we created earlier. You can also attach a new load balancer and create a target group for it.

NOTE — When naming your Auto Scaling Group, make sure you have no space just like I did, I got an error message when I tried to create it

After you’ve created your Auto Scaling group, go to your instance and copy the IP address and paste into your browser to see if the user data that was in the launch template works, if you see an image that’s identical to what’s below, then it worked

Stress Test

The next thing is to test if the Auto Scaling Group works, you can do this by sshing into one of the instance and performing a stress test, if the CPU utilization of the instance goes above the the 80% threshold, then an alarm should be triggered in CloudWatch which will make the Auto Scaling Group provision a new instance based on the parameters that was in place when me created it.

You can download and install the amazon-linux-extras library after sshing into the instance by using the command:

sudo amazon-linux-extras install epel -y

Then install the CPU stress tool on the instance using the command:

sudo yum install stress -y

Now you can run the stress tool on the instance by using the command

sudo stress --cpu 4 --timeout 800

After this is all done, an alarm is triggered and Auto Scaling group increased the number of added a new instance to the two instance already created.

Due to the stress on the CPU and the increased CPU utilization, another instance was added

The Auto Scaling Group is working as it should and you have successfully been able to see how Auto Scaling Group makes use of automatic scaling and management depending on your traffic . You can also see some of the features like health checks and scaling policies.

Thank you for reading, I hope you enjoyed it.

--

--