Introduction
We will learn to deploy an AWS Auto Scaling Group for a deployed EC2 instance. In this walk through, you will learn how to connect the Auto Scaling Group to an Application Load Balancer, and then use the AWS Launch Template to deploy our Auto Scaling Group. To have a better under standing of what the Auto Scaling does, I recommend you read the previous post about some core components and features of AWS Auto Scaling.
CREATE EC2 AMAZON MACHINE IMAGE
We will start with creating an EC2 AMI. I already deployed an EC2 instance from this post here. Once you deploy your instance, select the instance, under Actions button, select Images and Templates. Then Create Image.
![AMI image for EC2 instance](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/1.png?resize=434%2C262&ssl=1)
In the next window, input the name for your image. Also include the description. Choose a suitable size for the EBS that the AMI instance will use when deployed.
Then click the create Image.
![Name of the ami image. Create Image](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/2.png?resize=922%2C635&ssl=1)
You can check that the image is create. Click the AMI on the left, and you should see the AMI in the list.
![See the created image](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/3.png?resize=1090%2C120&ssl=1)
create target group for load balancer
Now that we have created the image for our EC2 instance, we can now create the Load balancer. The load balancer will route traffic equally among the EC2 instance fleet when the AWS Auto Scaling Group scales in or scales out. This will ensure no server is overworked.
We will create an Application Load Balancer, however, we first need to create the Target Group for Load Balancer. A target group is a collection of EC2 instance that the Application Load Balancer will route the traffic to. And since we will be using the servers deployed by our Auto Scaling Group, we will not need to specify a target here.
Select Instances target type. Enter the name and the protocol. Port 80 is default port for the server web browser.
![Create target group for aws load balancer](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/3a.png?resize=745%2C592&ssl=1)
In the Networking, select the VPC to deploy your Application Load Balancer. Make sure it is the same as where the AWS Auto Scaling Group will be deployed.
Use the HTTP1 or HTTP2 protocol version. And for the Health Check path, we specify the root path of our application.
![Select the https protocol for ELB target group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/3b.png?resize=576%2C646&ssl=1)
Leave the other settings as default and click Next.
![Click Next](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/3c.png?resize=595%2C31&ssl=1)
The next window is where you Register Target instance. Do not select any instance here. Then click the create Target Group.
CREATE LOAD BALANCER
Once we create the Target Group without registering any target, we will go ahead an configure our AWS Application Load Balancer.
Scroll down the left menu in you AWS EC2 console. Select Load Balancer. Then select Application Load Balancer.
![Application Load balancer configuration.](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/4.png?resize=691%2C589&ssl=1)
In the next window, enter the Load Balancer name, then select the Internet-Facing for the scheme. We use internet facing because our Load Balancer will be accepting traffic from the public IP address.
Select the IPv4 IP address type.
![Name the AWS ELB](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/4a.png?resize=730%2C333&ssl=1)
Select the VPC and Subnet for the Load Balancer.
![Select the vpc and subnet for the load balancer](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/4b.png?resize=725%2C586&ssl=1)
Then, select the Target Group you created earlier from the dropdown list. Also include the Protocol and Port number.
Security Tip: It is important to note that the Security Group should be refactored to allow only traffic from the Load Balancer security group only, while the Load Balancer security group would allow other public traffic.
![Add listener and routing for your application load balancer](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/4c.png?resize=732%2C365&ssl=1)
Then click the Create Load Balancer.
![create aws load balancer](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/4d.png?resize=787%2C55&ssl=1)
CREATE LAUCH TEMPLATE
Now we have the Application Load Balancer ready, we will create a Launch Template for our AWS Auto Scaling Group. The Launch Template will carry the definition of instance that ASG will spin up.
Click the Launch Template at the site bar of the EC2 dashboard. Select the Create Launch Template.
![Create EC2 launch template for AWS auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/5.png?resize=1010%2C239&ssl=1)
Enter a name to identify your launch template. Also add the description.
![name the launch template](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/5a.png?resize=635%2C390&ssl=1)
Next, under the Application and OS Images, select the My AMIs, then select Owned by me. In the dropdown, select the AMI you created from the EC2 instance earlier.
![select the free tier instance type for aws auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/5c.png?resize=634%2C380&ssl=1)
Check the summary and then Create Launch Template.
![Check the summary for launch template and create](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/5d.png?resize=295%2C360&ssl=1)
Once it is created, check that it is created, and take note of the version number.
![confirm launch template](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/5e.png?resize=881%2C76&ssl=1)
CREATE EC2 AUTOSCALING GROUP
And once again, scroll to the bottom of the menu in the AWS EC2 dashboard and select Auto Scaling Group. Then click Create Auto Scaling Group.
![Create ASG](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6.png?resize=357%2C205&ssl=1)
Give the Auto Scaling Group a name. Then select the Launch template you created earlier from the dropdown list. Take note of the version too.
![Add name for aws auto scaling group and select the launch template](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6a.png?resize=634%2C417&ssl=1)
Select the same VPC where you deployed the Load Balancer and the EC2 instance. Also select the Availability Zone.
![Select the vpc and subnet for aws auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6b.png?resize=640%2C453&ssl=1)
Leave the other settings at the default. Then click Next.
![click next](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6c.png?resize=646%2C282&ssl=1)
In the next window, you will select the Load Balancer that ASG will work with. Select Attach to an Existing Load Balancer. Then select the Choose from Load Balancer Target Groups. Select the Target Group from the dropdown list.
![select the application load balancer to attach to aws auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6d.png?resize=650%2C499&ssl=1)
In the Health Checks, select the check box for Turn On Elastic Load Balancing Health Checks. Make the grace period 300 seconds.
![Select the Health check for Load Balancer](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6e.png?resize=634%2C447&ssl=1)
Select the check box to enable the group metric collection within cloudwatch. Then click Next.
![Enable cloudwatch monitoring for aws auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6f.png?resize=645%2C261&ssl=1)
In the next window, select the Desired, Minimum, and Maximum capacity for the size of instance that ASG will work with.
![create the size of your auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6g.png?resize=583%2C300&ssl=1)
Then use the Target Tracking Policy to tell Auto Scaling Group the condition to scale the instance. Here is used the CPU Utilization at 80%. I also specify a 300 seconds warm up period. Your could be lower.
![Configure target tracking for your aws auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6h.png?resize=635%2C491&ssl=1)
Click Next.
![click next](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6i.png?resize=420%2C55&ssl=1)
Review all the settings and the click the Create Auto Scaling Group once you are satisfied.
![Skip sns and create auto scaling group](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/6j.png?resize=345%2C41&ssl=1)
check the instances deployed for confirmation
You can confirm the Auto Scaling Group is created by checking the list of the AWS creaated.
![confirm auto scaling group is created](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/7.png?resize=1024%2C140&ssl=1)
Also when you check the list of deployed EC2 instance, you should also see that AWS has deployed more servers for use based on our configuration.
![confirm aws auto scaling group creates the instance](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/7a.png?resize=1024%2C93&ssl=1)
…and our server is working.
![Instance check passed.](https://i0.wp.com/oxla.io/wp-content/uploads/2023/05/7b.png?resize=650%2C59&ssl=1)
CONclusion
In this post, we have been able to configure AWS AutoScaling Group and Elastic Load Balancer to make our EC2 instance server more resilient, reliable, fault tolerant, and secure.
Leave a Reply