~Instance Launching using a Load Balancer and Auto Scaling Group~

Asonti Ginn
Code Like A Girl

Today’s Goals:

~Create a VPC, attach its subnets, and route tables to an Internet Gateway.

~Create a Launch Template that installs Apache.

~Launch Instances using an Auto Scaling Group and Load Balancer.

Key Terms:

~Auto Scaling Group: Helps you manage and scale the number of instances you need by implying the maximum and minimum amount of instances you want.

~Load Balancer: A load balancer is used to distribute traffic, like http, https, and TCP. There are 4 types of load balancers: Application, Network, Gateway, and Classic.

~Launch Template: Used to make instances with the same settings, similar to making your own personal default settings for your instances.

~Internet Gateway: Enables communication between your VPC and the Internet.

~Apache: A free Open-source web server, it can run on a wide range of Operating Systems, is highly customizable, and contains strong security features.

~Instance: A virtual server inside the AWS Cloud.

~VPC: Virtual Private Cloud inside of AWS. Some features consist of Subnets, Route tables, various Gateways, Elastic IPs, and more.

~Subnets: A range of IP Addresses, you can launch EC2 instances into subnets.

~Route Table: These are used for routing traffic with a specific set of rules.

Prerequisites

~An Amazon AWS account.

~Basic understanding of how to use AWS.

VPC Setup

We will begin by setting up the VPC, adding subnets, a route table, and an Internet Gateway.

The VPC creation is first. Enter the VPC Management Console and create a new VPC.

Here they will ask for a name and IPv4 CIDR. You can set the name to something unique to make this VPC stand out. I will be labelling everything based on my week seven project.

For your CIDR block, we will be using the IPv4 CIDR: 10.10.0.0/16.

Now we will create an Internet gateway and attach it to the VPC.

Once made select “Actions” in the right corner and add it to the VPC we made above.

Next, is subnet creation. We will be making three subnets for this project. Back in the VPC management console click create subnet.

Name your subnets in correspondence with each other to make it easy to tell them apart from your other subnets. I named mine 1pub, 2pub, and 3pub.

Each subnet needs to have a different Availability Zone. In respect to my region, I am closest to us-east-1 but yours may be different based on location. I will use Availability Zones us-east-1a through us-east-1c.

For the CIDR blocks, I used the 1pub, us-east-1a with CIDR Block 10.10.1.0/24. Subnet 2 I used 2pub, us-east-1b with CIDR Block 10.10.2.0/24. With the last subnet, I used 3pub, us-east-1c, and CIDR Block 10.10.3.0/24.

Once your subnets are created, we need to attach them to the routeing table associated with the VPC we created. Under route tables in the console, select the routeing table that has your VPC attached (this route table will not have a name). I strongly suggest you name this route table.

Select the route table Subnet associations, find the explicit subnet associations, and select edit subnet associations. Now add all three subnets to the route table.

After adding the subnets, we can now add the internet gateway—select routes and edit. For the destination, we need to set it to 0.0.0.0/0. Our Target is the internet gateway. Select the gateway we made above and save the changes.

Now we have connected all of our VPC settings.

Create Launch Template

Inside the EC2 Console, we need to select Launch Template and create one.

We need to name the template and then select the AMI. I will be using the 2023 AMI and a t2.micro instance.

Next are the key pair settings. For this project I want to create a new key pair, you can use a previously made key pair. If you use an already-made key pair disregard the picture below.

We do not want to include subnets in your launch template. Next is security groups. We want our group to allow HTTP traffic from anywhere. Make sure you use the correct VPC.

Below the security group settings is a tab for advanced settings. Open advanced settings and enable “Auto-assign public IP”.

Lastly, scroll to the very bottom of the screen and select “Advanced details.” Again, scroll to the very bottom and in the User Data field, type the bash script provided below. This bash script installs and enables Apache to your instances.

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

Now you can save your template.

Autoscaling and Load Balancing

When we make our Auto Scaling Group, we want to use the Launch template we made above.

Network settings are next. More than likely, your VPC will be set to default, change to the one we made above.

Then we need to add all 3 of the subnets we created.

On the next page, we will be asked to create a new load balancer. We need an Application load balancer so we can use HTTP. Create a name and make it Internet-facing. Your subnets are already attached, but we need to add a listener.

The listener is automatically set to port 80. Select create target group beside it and add a name.

Now we need to set the group size. We want three instances; therefore desired capacity needs to be “3”, minimum capacity “2”, and a Maximum capacity of “5”.

We don’t need to change any more settings. You can select “Skip to review” and launch your Auto Scaling Group.

The load balancer, your instances, and auto-scaling group have all been created.

The security group settings of the Load balancer need to be edited because it is automatically made with the default VPC. Return back to your load balancer, select security, and edit.

Remove the default security group, attach it to the security group we made earlier, and save the changes.

Return back to your load balancer and refresh the page. Copy and paste your DNS name into your browser, and your webpage should run.

You just learned how to launch Instances using Auto scaling and Load Balancing.

For more easy-to-follow articles, follow me on Medium!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Code Like A Girl

Welcome to Code Like A Girl, a space that celebrates redefining society's perceptions of women in technology. Share your story with us!

Written by Asonti Ginn

Hey! I am taking you on my Cloud engineering journey with easy to follow, how-to articles. All provided with an under 10-minute read and PLENTY of pictures!☁️

No responses yet

Write a response