Setting Up a Load Balancer and Auto Scaling

I will finish off demonstrating how I configured a Load Balancer and an AutoScaling Group. Let’s do it!

Additional Subnet

To launch an autoscaling group, eventually, we’ll need multiple VPC subnets. So I went ahead and created one more public subnet in my VPC.

For my Public subnets I am following a pattern of 10.0.1.0/24 -> 10.0.2.0/24 -> 10.0.3.0/24. I put 10.0.2.0/24 for this second one. To make it public, I need to enable “Auto-assign public IP”

Application Load Balancer

First, I like to create a target group to have ready for when I make my Load Balancer. (Creating ALB 1)

I choose option ‘instances’ so the load balancer will know to direct traffic to my EC2 instances (Creating ALB 2)

The default health check path and settings are good as they are, but for my instances I can make the interval between health checks a little faster. (Creating ALB 3-4)

After that, I need to register my target, but that can be done afterwards too. (Creating ALB 5-6)

To create the load balancer, I choose Application LB, give it a name, leave the rest, and set up the VPC. The VPC is the one I created previously, and with it comes the two different availability zones I configured. Then connect the AZs with their respective subnets. (Creating ALB 7-10)

Next, all I have to do is choose the security group and target group, both of which I already made. (Creating ALB 12-14)

Autoscaling Group (ASG)

Launch Template

To create an Autoscaling group for my instance, first, I need to make a

launch template off of my original instance.

 

So I had some issues with this. Initially, when I created the launch template and ran it in ASG, my instances were failing. After ssh’ing in to one of them, I noticed that none of the contents from my original instance made it over to the new ones. Therefore, I created an EBS snapshot of the original, then I modified the template and inserted the ELB snapshot. (Launch Template 1-3)

In the launch template, everything is already configured by itself. I have to give it a name, and add a new EBS volume with the snapshot. Requirements also specify to pick a good device name (Launch Template 5-9)

Autoscaling Group

We have the usual setup: name, select VPC and my two subnets, and choose my Application Load Balancer. All of that is done and ready. (Creating ASG 1-5)

With ASGs I can select the minimum amount, the maximum, and my desired amount of instances. (Creating ASG 6)

Everything complete! (Creating ASG 7-8)

Result

Now there should be multiple instances behind my little webpage, and traffic should be distributed equally between them. Normally, I would display different messages on each of the instances so when I refresh the page, the message will change each time as traffic is hitting a different instance.

However, if I wanted to show one WordPress site, I would probably want it to be identical across all instances, and this is the setup I have going on now. So, all the instances display the same message. 

All Done