AWS High Availability Lab: EC2, ALB & Auto Scaling
Learn how an AWS lab uses an Application Load Balancer, EC2 Auto Scaling, and CloudWatch to improve availability, spread traffic, and respond to demand.
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 10AWS High Availability Lab: EC2, ALB & Auto Scaling This article
One EC2 Instance Worked. That Was the Problem.
How I Built a Highly Available, Auto-Scaling Application on AWS
AWS Hands-On Lab 4 | EC2 | Application Load Balancer | Auto Scaling | CloudWatch | High Availability
The application was working. Why change anything?
Imagine launching an application, getting positive feedback from users, and watching adoption grow. Everything looks good. Until you ask one uncomfortable question:
What happens when the server running that application cannot keep up?
A working application proves that your software can run. It does not prove that the application can survive a server failure, distribute increasing traffic, or recover automatically.
That was the challenge behind AWS Lab 4. The Employee Directory application had already been deployed successfully. The HR team loved it. But management anticipated higher demand and wanted to address potential performance problems before employees began experiencing them.
The assignment was to move beyond a single EC2 instance and build an architecture capable of distributing traffic, maintaining multiple application instances, and adjusting compute capacity based on demand.
This was not just a lesson in clicking through the AWS Console. It was an exercise in changing how an application behaves when infrastructure conditions change.
1. Understanding the Starting Architecture
Before creating anything, I needed to understand what the lab had already provided.
The application was running on one Amazon EC2 instance inside a public subnet. Its supporting environment included networking, storage, database access, and permissions that had already been configured.
The initial architecture looked like this:
Internet → Internet Gateway → Public Subnet → Single EC2 Instance → Employee Directory Application
The problem was not that this architecture could not serve users. The problem was that the application depended on one compute instance.

- Caption: Before high availability: one application instance serving requests
Resources the lab had already provisioned
This distinction matters because the lab was not built from an empty AWS account.
Resource | What was available |
|---|---|
AWS Region | ap-southeast-2 |
VPC | Lab VPC |
Internet Gateway | Preconfigured |
Public Subnets | Two, in different Availability Zones |
Route Table | Internet route already configured |
Security Groups | Lab-provided groups |
EC2 Instance | Web Application |
S3 | Images bucket and installation bucket |
DynamoDB | Existing application table |
IAM | Instance role with S3 and DynamoDB permissions |
Web Application | Employee Directory, already deployed |
The lab also supplied these environment-specific values:
- ImagesBucket:
labstack-4cd503cf-e20b-4d8f-a723-ff5e-imagesbucket-widnln8odltk
- InstallationBucket:
labstack-4cd503cf-e20b-4d8f-a72-installationbucket-fxjl6w08vgpw
- PublicWebApplicationURL:
http://ec2-32-236-171-41.ap-southeast-2.compute.amazonaws.com
These identifiers belong to the supplied lab environment and should not be treated as reusable resources in another AWS account.
The first task was verification, not modification.
Inside the EC2 Console, I reviewed the instance named Web Application and checked that it was running. I also examined its instance configuration, networking, and security information.
Next, I opened the Employee Directory through its public URL.
This established the baseline: the application was accessible before introducing a load balancer or additional instances.

Shows the EC2 Instances page with:
- Web Application instance
- Running state
- Instance details
The application included an Administration → Configuration page. This page displayed the Availability Zone serving the application, along with S3 and DynamoDB configuration information.
The Availability Zone field would become important later.
At this stage, there was only one application instance. Once the load balancer and Auto Scaling group were operating, the same page could help demonstrate requests reaching instances across different Availability Zones.
Employee Directory Configuration Page


Highlights:
- Availability Zone
- S3 configuration
- DynamoDB status
Lesson: Before making infrastructure changes, identify a reliable way to verify the application's behavior. Without a baseline, even a successful deployment can be difficult to validate.
2. Creating the Application Load Balancer
A second server alone would not solve the problem.
Users needed one consistent entry point. Behind that entry point, AWS needed to determine which application instances were healthy and eligible to receive traffic.
This is the role of an Application Load Balancer (ALB).
Rather than having users connect directly to one EC2 instance, requests would reach the ALB, which would forward them to registered targets.
The first step was creating the target group.
I configured the target group using the settings specified in the lab:
Setting | Configuration |
|---|---|
Target Group Name | lab-app-target-group |
Target Type | Instances |
Healthy Threshold | 2 |
Unhealthy Threshold | 5 |
Health Check Timeout | 20 seconds |
Health Check Interval | 30 seconds |
Initial Registered Target | Web Application |
A target group does more than hold a list of servers. It defines where the load balancer can send traffic and uses health checks to evaluate whether those targets are suitable.
[Target Group and Health Checks]









Next came the load balancer itself.
The configuration used:
- Name:
Web-Application-ALB
- VPC: Lab VPC
- Availability Zones: Both available zones
- Security Group: LoadBalancerSG
- Target Group: lab-app-target-group
The lab used HTTP on port 80.
Selecting subnets in two Availability Zones gave the load balancer a multi-AZ network configuration. It did not, by itself, make the application highly available. That required healthy application targets across the zones.

Caption: The ALB provides a stable entry point before compute capacity is expanded.
Once the ALB reached its Active state, I used its DNS name to access the Employee Directory application.
This was the first important architecture change.
The application was no longer being reached only through the original instance's public address. Users could access it through the load balancer's DNS endpoint.
However, the system still had a single application target. The ALB had improved traffic routing, but the compute layer was not yet redundant.
First insight: A load balancer is not a substitute for redundancy. It becomes more valuable when multiple healthy application instances are available behind it.
3. Creating a Launch Template: Making Servers Repeatable
If the application needed more servers, AWS had to know how to create them.
Manually launching and configuring every new EC2 instance would introduce delays and inconsistency.
This is why the next task was creating a launch template.
The lab used the following configuration:
Setting | Value |
|---|---|
Launch Template | lab-app-launch-template |
Description | A web server for the employee directory app |
AMI | Amazon Linux 2023, 64-bit x86 |
Instance Type | t3.micro |
Key Pair | Don't include in launch template |
Security Group | Web Security Group |
IAM Instance Profile | EmployeeDirectoryAppRole |
Metadata Version | V1 and V2, token optional |
The launch template defined the settings required for Auto Scaling to create replacement or additional instances.








The most important part of the template was the user data script.
A new EC2 instance needed to become a working application server automatically.
The supplied script was designed to perform system updates, install Node.js 20, install the stress-testing utility, download the application from S3, configure environment variables, install application dependencies, and launch the Employee Directory.
Its configuration began with three environment-specific values:
IMAGES_BUCKET=UPDATE_WITH_IMAGES_BUCKET_NAMEINSTALLATION_BUCKET=UPDATE_WITH_INSTALLATION_BUCKET_NAMEYOUR_DEFAULT_AWS_REGION=UPDATE_WITH_ACTUAL_REGIONThe installation process used the lab's S3 installation bucket, extracted the application into
/var/app , configured the images bucket and AWS Region, and started the Node.js application using npm start .The actual lab supplied the complete bootstrap script. The snippet above shows only the environment values that needed to be customized.

This introduced an important infrastructure principle:
A server should be reproducible, not irreplaceable.
If an instance disappears, the application should not depend on someone remembering how to configure its replacement.
A launch template combined with automated bootstrap makes it possible for EC2 Auto Scaling to create new application instances using a consistent specification.

Caption: Repeatable deployment is a prerequisite for useful automatic scaling.
Lesson: Automation is not merely about reducing manual effort. It reduces the number of decisions that must be made during a failure or traffic spike.
4. Building the Auto Scaling Group
With a launch template ready, I could define how many application instances AWS should maintain.
The Auto Scaling group used the following settings:
Setting | Value |
|---|---|
Auto Scaling Group | app-asg |
Launch Template | lab-app-launch-template |
VPC | Lab VPC |
Subnets | Public Subnet 1 and Public Subnet 2 |
Desired Capacity | 2 |
Minimum Capacity | 2 |
Maximum Capacity | 4 |
Target Group | lab-app-target-group |
ELB Health Checks | Enabled |

The distinction between these capacity values matters.

Minimum capacity establishes the lower boundary. Desired capacity is the number of instances the group attempts to maintain at a particular moment. Maximum capacity places an upper limit on the group's size.

The lab began with two desired instances and allowed the group to grow to four.



Caption: Multiple application instances across Availability Zones reduce dependence on one compute instance.


The lab also introduced notifications.

During Auto Scaling group creation, I configured an Amazon SNS topic named
lab-app-sns-topic and added an email recipient.
The recipient needed to confirm the SNS subscription before receiving the configured notifications.




Notifications matter because infrastructure actions should be observable. An automatically changing system is useful, but operators still need visibility into significant changes.

The scaling policy was added after the Auto Scaling group had been created.
This sequence was intentional. The lab noted that AWS service dependencies including monitoring metrics and target group integration may need time to initialize.
The target tracking policy used:
Setting | Value |
|---|---|
Policy Name | cpu-target-tracking-policy |
Policy Type | Target Tracking |
Metric | Average CPU Utilization |
Target Value | 30% |
Instance Warmup | 300 seconds |
Scale-In | Enabled |
Think of this as a feedback system.
When the group's CPU utilization rises above its configured target, target tracking can add capacity. When demand decreases, the policy can reduce capacity within the group's configured limits.
The 300-second instance warmup helps prevent newly launched instances from immediately distorting scaling decisions while they initialize.
At this point, the target group could contain three application instances: the original manually deployed Web Application instance and two instances launched by the Auto Scaling group.
But there was a problem.
The original instance was not managed by the new Auto Scaling group.
That means its capacity was outside the group's desired, minimum, and maximum instance counts.
The lab therefore instructed us to confirm that the two new instances were healthy and then terminate the original instance.
This was appropriate for the disposable lab environment. In a production migration, the safer approach would be to deliberately drain and deregister the old target before terminating it, after validating replacement capacity.



- Original Web Application instance
- Two newly launched instances
- Healthy status of the Auto Scaling-managed targets
After the original instance was terminated, the application was accessed again through the ALB DNS name.


The expected result was simple but important: the Employee Directory remained available through the load balancer.

The architecture no longer depended on the original manually created EC2 instance.
This was the transition from one application server to a group of managed application instances.
5. Testing High Availability and Horizontal Scaling
Creating infrastructure is not the same as validating it.
The final task was to test whether the new architecture behaved as intended.
First, I returned to Administration → Configuration in the Employee Directory and refreshed the page several times.
The page displayed the Availability Zone of the instance serving the request.
Seeing the displayed Availability Zone change would provide evidence that requests were reaching instances in different zones. Because load balancing behavior can be affected by connection reuse and other factors, the value is not guaranteed to alternate on every refresh.

Caption: The same application endpoint can serve requests through targets in different Availability Zones.

The next test introduced CPU pressure.
The Employee Directory included an administration tool named Stress Application Server For.
I selected the 10-minute stress-test option.
The application displayed a Stressing... message, indicating that the simulated workload had begun.
This test was designed to increase CPU utilization and create conditions that could trigger the target tracking policy.



The expected behavior was for elevated CPU demand to drive a scaling decision, subject to the group's capacity limits and policy behavior.
To observe the result, the lab directed us back to the target group's Targets tab.
If CPU utilization remained high enough for the target tracking policy to act, the group could provision another instance. The new instance would initialize, register with the target group, and become eligible for requests after passing health checks.
The SNS notification could provide another signal that a scaling event had occurred.




The lab's intended outcome was to validate both multi-AZ traffic distribution and horizontal scaling.
It is worth separating those two results.
Multi-AZ load balancing demonstrates that requests can reach different healthy application instances. CPU-driven scaling demonstrates that the control system can respond to demand by changing compute capacity.
A successful stress test does not, by itself, prove that the application can withstand every infrastructure failure, meet a particular latency target, or recover without interruption.
Those claims require additional testing and operational measurements.
6. What This Lab Taught Me From First Principles
The AWS Console makes infrastructure look like a collection of services.
First-principles thinking helps explain why those services exist and how they work together.
Principle 1: Availability begins with eliminating single points of failure
A single EC2 instance has finite capacity and represents one compute dependency.
Its failure can remove the application's only serving endpoint.
Adding a second independently running application instance reduces that dependency.
Placing instances across Availability Zones provides further separation because the application no longer relies on compute resources in only one zone.
First-principles takeaway: If a component can fail, ask whether the system can continue without it.
Principle 2: Separate traffic routing from compute capacity
The load balancer and application instances solve different problems.
The ALB determines which healthy targets receive requests.
EC2 instances provide compute resources to process those requests.
Separating the two allows application instances to change without requiring users to connect to a different server address.
First-principles takeaway: Keep the entry point stable while allowing the underlying compute resources to change.
Principle 3: Desired state is more reliable than manual intervention
The Auto Scaling group was configured to maintain at least two instances.
Instead of waiting for a human to notice that an instance disappeared, EC2 Auto Scaling can launch replacements to maintain its desired capacity.
This is a change from manually managing individual servers to declaring how the infrastructure should behave.
First-principles takeaway: Describe the outcome the system must maintain, then automate the mechanism that maintains it.
Principle 4: Automatic scaling is a feedback-control problem
The target tracking policy has four important elements:
- Signal: Average CPU utilization
- Target: 30%
- Action: Adjust instance capacity
- Boundary: Two to four instances
Warmup time, metric collection, bootstrap time, and health checks affect how quickly additional capacity becomes useful.
Scaling is not instantaneous. It is a feedback loop operating with measurement and provisioning delays.

Caption: Auto Scaling continuously adjusts capacity in response to measured demand.
First-principles takeaway: Before automating a response, understand what is being measured and how long the response takes.
Principle 5: Replaceable compute depends on shared application state
The lab had already provided Amazon S3 and DynamoDB, along with an IAM role that allowed application instances to access those services.
That arrangement was important.
The application did not need to rely entirely on files or data stored on one particular EC2 instance.
New instances could use the same configured application resources.
The lab's architecture illustrates why externalizing persistent application data makes horizontal scaling more practical.
First-principles takeaway: If an application server must be replaceable, important application data should not exist only on that server.
7. Lessons Learned From the Lab
Lesson 1 A healthy instance is not the same as a highly available application.
The original Employee Directory was running successfully. That did not remove its single-instance dependency.
Availability needs to be evaluated at the architecture level.
Lesson 2 A load balancer needs healthy, redundant targets.
Creating an ALB was an important first step. The larger availability benefit came when the target group contained multiple Auto Scaling-managed application instances.
Lesson 3 Launch templates turn infrastructure into a repeatable process.
A server that requires manual installation is difficult to scale reliably.
Automated bootstrap makes it possible to provision new application servers using a consistent configuration.
Lesson 4 Health checks and scaling signals serve different purposes.
Health checks determine whether a target should receive traffic.
CPU target tracking determines whether the Auto Scaling group should adjust capacity.
A healthy instance can still be under heavy load. A heavily loaded instance does not automatically mean it has failed a health check.
Lesson 5 Scaling policies need testing, not assumptions.
Configuring a 30% CPU target does not guarantee an immediate scale-out.
Workload distribution, average CPU utilization, warmup periods, and instance startup times affect the observed results.
Monitoring the scaling activity and actual capacity changes is essential.
Lesson 6 A functional lab architecture is not automatically production-ready.
The lab used public subnets, HTTP, and optional IMDSv2 tokens because it was a guided training environment.
For production, I would evaluate private application subnets, HTTPS, restricted security groups, IMDSv2 enforcement, appropriate application monitoring, and secure management access.
The lab established core availability and scaling concepts. Production engineering would require further hardening.
8. DIY: Apply These First Principles Yourself
Reading about Auto Scaling is useful.
Testing its behavior is better.
Here is a manageable exercise that applies the concepts without pretending that the lab started with an empty AWS account.
First, understand what the lab did for us
AWS Lab already included several prerequisites that would otherwise take additional time to build.
The lab supplied the VPC, Internet Gateway, two public subnets in separate Availability Zones, route table, security groups, S3 buckets, DynamoDB table, IAM role, original EC2 instance, and running Employee Directory application.
It also provided the application archive and bootstrap installation resources.
That allowed the guided work to focus on the target group, ALB, launch template, Auto Scaling group, scaling policy, and validation.
In a fresh AWS account, you would need to supply or configure those dependencies yourself.
DIY objective
Build a small application that:
- Runs on two EC2 instances.
- Uses one Application Load Balancer.
- Replaces an instance when necessary.
- Can increase its capacity from two instances to a maximum of four.
- Allows you to observe the relationship between health, demand, and scaling.
Step 1 Prepare a minimal test environment
You can simplify the exercise by using an existing suitable VPC with subnets in two Availability Zones, such as a properly configured default VPC.
You will need:
- Two subnets across different Availability Zones
- Internet connectivity or another suitable way for instances to obtain software packages
- A security group allowing HTTP traffic to the ALB
- An application-instance security group allowing HTTP traffic from the ALB security group
- Permissions to create EC2, ELB, Auto Scaling, and CloudWatch resources
For learning, a basic Nginx web page is enough. There is no need to recreate the Employee Directory's DynamoDB and S3 functionality just to test load balancing and replaceable compute.

Step 2 Make each instance identify itself
To verify traffic distribution, each instance should display information identifying the server that responded.
For Amazon Linux 2023, a simple EC2 user data script can install Nginx and write an instance-identification page.
Example:
#!/bin/bashset -euxo pipefail
dnf install -y nginx
TOKEN=$(curl -fsS -X PUT \ http://169.254.169.254/latest/api/token \ -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
INSTANCE_ID=$(curl -fsS \ -H "X-aws-ec2-metadata-token: $TOKEN" \ http://169.254.169.254/latest/meta-data/instance-id)
AZ=$(curl -fsS \ -H "X-aws-ec2-metadata-token: $TOKEN" \ http://169.254.169.254/latest/meta-data/placement/availability-zone)
cat > /usr/share/nginx/html/index.html <<EOF<h1>High Availability DIY Lab</h1><p>Instance: $INSTANCE_ID</p><p>Availability Zone: $AZ</p>EOF
systemctl enable --now nginxThis example uses IMDSv2 to obtain EC2 metadata.
The script assumes the instance can access the required package repository and that the Amazon Linux 2023 image includes the expected utilities.
It is a separate DIY example, not the original Employee Directory installation script.
Step 3 Create the target group and ALB
Create an instance-based target group with an HTTP health check on
/ .Create an internet-facing Application Load Balancer using subnets in two Availability Zones, associate the appropriate security group, and configure an HTTP listener forwarding requests to the target group.
For a real application, prefer HTTPS with a valid certificate. HTTP is used here only to keep this disposable exercise small.
Step 4 Create the launch template and Auto Scaling group
Create a launch template using Amazon Linux 2023, a small supported instance type, the web-server security group, and the Nginx user data script.
Then create an Auto Scaling group associated with the target group.
Start with the lab's capacity configuration:
Setting | Value |
|---|---|
Minimum | 2 |
Desired | 2 |
Maximum | 4 |
CPU Target | 30% |
Instance Warmup | 300 seconds |
Enable Elastic Load Balancing health checks and use both Availability Zones.
Be aware that actual instance-type availability and cloud costs depend on your account and Region.
Step 5 Validate the first principle: redundancy
Wait for two application instances to launch and pass their health checks.
Open the ALB DNS name in your browser.
Refresh it and inspect the displayed instance ID and Availability Zone. You can also use separate HTTP requests to help observe responses.
Because load balancers may reuse connections, each refresh is not guaranteed to reach a different instance.
The objective is to establish that more than one healthy instance can serve the application.
DIY success check: Two registered, healthy application instances are serving behind one load balancer.
Step 6 Validate the second principle: automatic recovery
In this disposable environment, terminate one EC2 instance managed by the Auto Scaling group.
Observe the Auto Scaling group's activity history.
The group should work toward restoring the desired instance count by launching a replacement, assuming sufficient capacity and successful provisioning.
Monitor the replacement instance until it passes the target group's health checks.
This tests the difference between a manually managed server and a desired-state system.
DIY success check: The Auto Scaling group returns toward its configured desired capacity without manually launching a new EC2 instance.
Step 7 Validate the third principle: elasticity
Start with a simple control-plane test.
Temporarily raise the group's desired capacity from two to three within its configured limits.
Confirm that a third instance launches, initializes, and becomes healthy. Then restore the desired capacity.
This proves the launch template and Auto Scaling group can add compute capacity, but it does not yet prove CPU-driven automatic scaling.
For that, generate a controlled CPU workload on the lab instances using an approved instance-management method, such as AWS Systems Manager, and observe CloudWatch CPU utilization and Auto Scaling activity.
Do not assume that high CPU on just one instance will trigger scale-out. The policy uses average CPU utilization across the Auto Scaling group.
DIY success check: You can distinguish manual capacity adjustment from a scaling-policy action and find evidence of each in the AWS Console.
Step 8 Compare what you observed
Record the results in a short experiment table.
Experiment | What to observe |
|---|---|
Two healthy instances | Target group status |
Requests through the ALB | Instance IDs and AZs |
Terminate one managed instance | Replacement activity |
Increase desired capacity | Additional instance launched |
Generate CPU pressure | CPU metric and policy activity |
Return to normal demand | Scale-in behavior |
If automatic scale-out does not happen, investigate the metrics and activity history before changing the policy. An unsuccessful scaling attempt can reveal as much about the system as a successful one.
- Healthy targets
- Auto Scaling activity
- CPU utilization graph
- Instance capacity before and after the test
Step 9 Clean up the environment
When the experiment is complete, remove the resources created for the DIY exercise, including the Auto Scaling group, launch template, load balancer, target group, and any test-specific resources that are no longer required.
Check that instances have terminated and review your account for remaining chargeable resources.
EC2 instances, Application Load Balancers, monitoring resources, and associated infrastructure may incur charges outside a managed training lab.
9. The Bigger Lesson: High Availability Is a System Property
What makes this lab useful is not the number of AWS services involved.
It is the relationship between them.
The Application Load Balancer distributes requests.
The target group identifies eligible application instances.
The launch template describes how new servers are created.
The Auto Scaling group maintains and adjusts compute capacity.
CloudWatch metrics provide signals for scaling decisions.
S3 and DynamoDB provide application resources that can be shared by multiple compute instances.
Together, these components support an application architecture that is less dependent on any one server.
The most useful shift in thinking is this:
Stop designing only for the moment when everything works. Start designing for the moment when something changes.
Traffic grows.
Instances become unhealthy.
New capacity takes time to initialize.
Individual servers eventually need replacement.
A well-designed application does not require every component to remain unchanged in order to keep serving users.
It needs clear dependencies, enough redundancy, reliable signals, and tested recovery mechanisms.
That is the difference between deploying an application and engineering an application that can adapt.
Open to Cloud Ops Remote and technical writing projects.
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 10AWS High Availability Lab: EC2, ALB & Auto Scaling This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article