Amazon EC2 Autoscaling

Dane Forslund
4 min readMay 9, 2022

--

Rather than supplying your own limited computing resources, consider EC2 and Autoscaling!

Amazon’s EC2 service (Elastic Compute Cloud) was designed to help deploy applications through a virtual machine, represented by a physical server.

This is incredibly helpful for growing organizations that have dynamic computing needs. So, instead of providing and maintaining your own physical server, you can use Amazons EC2 instances over the air.

This is: Cost Effective, has Extensive Safety Features, and is Highly Reliable and Efficient (as will be shown in this project)

Cost — “Pay as you go, pay for what you use, pay less as you use more, and pay even less when you reserve capacity”. (AWS Whitepaper)

has Extensive Safety Features …

And is Highly Reliable and Efficient— As we will show through EC2 and Autoscaling

In this project, we are going to:

  1. Create a launch template with a minimum of 2 instances & maximum of 5.
  2. Add an auto-scaling group that will span at 4 subnets.
  3. AND we will simulate a failure by terminating one of the instances.

Prerequisites:

1) An AWS Account

2) A preconfigured key pair (preferred) and security group with rules like this:

FYI: If I do not address certain options available, that means I left them as default. 

Step 1 — Navigate to the “Launch Templates” option in EC2 Services then click “Create Launch Templates”.

Next add your template name and description and choose an Amazon Machine Image (AMI). We will use Amazon Linux for this project.

Then you will add your Instance Type and your Key Pair for security.

Add your security group…

Add your storage requirements…

Now, scroll to the bottom and select “Advanced Details”. Continue to scroll to the bottom again and add this to your “User Data”.

#!/bin/bash
#update server, install httpd (apache) and create test pageyum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<html><body><h1>It's Launch Time, What's for Launch?</html></body></h1>" > /var/www/html/index.html

This will add a bootstrap script that installs updates, an Apache webserver, and will create a test webpage in our instance upon “booting”.

Alright, Let’s finalize this portion by clicking, “ Create Launch Template”. Then after you see a “Success” flag, go ahead and click “View Launch Template”.

Once you are able to see your Launch Template, and click on it’s ID. When you are able, click “Actions” and select the “Create Auto Scaling group” option from the dropdown menu.

Then you can name your Auto Scaling Group, and then scroll down and click Next. (I named mine, “ItsLaunchTimeASG”)

On this next page, I am using the default VPC, and then I am going to add 4 subnets for higher availability. Afterwards you can click, “Next”!

When you enter the, “Configure advance options” page, you can click “Next” again…

On this page you can add your “desired”, “Minimum”, and “Maximum” number of instances operating at one time. This is helpful, because when CPU loads fluctuate, you are able to have your needs met without always operating at your maximum load. So when CPU loads are lower, you aren’t paying for your max.

Let’s move on, and click “Next”. Then click it again on the “Add Notifications” page, and the “Add tags” page.

After you have reviewed your ASG, go ahead and click, “Create Auto Scaling Group”.

Now, it’s time to test things out by finding our new project instances, copying the Public IPv4 address, and launching our site!

We did it!

Lastly, lets go ahead and show what happens when one of our instances fail (we will do this by terminating one of them).

Now we can check the results!

This is why we rely on AWS EC2 Instances and Autoscaling. Should one server go down, we are still able to operate. Should our CPU usage fluctuate, we can add other instances to relieve computing needs.

Thank you for reading!

--

--

Dane Forslund

DevOps | Cloud | AWS enthusiast. I believe my most successful moments have derived from patient leadership, proactive resolve, and often adversity.