Project Overview: Building Resilience on AWS
Deploying a web application that remains accessible and performs reliably, even when underlying infrastructure components fail, is a core challenge for any modern development team. This project outlines a practical, hands-on approach to achieving high availability on Amazon Web Services (AWS) by integrating several key services: Application Load Balancer (ALB), EC2 instances managed by an Auto Scaling Group, and the inherent self-healing capabilities of AWS infrastructure across multiple Availability Zones (AZs).
The architecture centers around Amazon EC2 instances that host an Apache-based web application. These instances are not managed individually but are part of an Auto Scaling Group. This group ensures that the correct number of instances are running at all times, automatically adjusting to demand and replacing unhealthy instances. The entry point for all user traffic is an internet-facing Application Load Balancer. The ALB distributes incoming HTTP requests across a pool of healthy EC2 instances registered in a Target Group. This distribution is crucial for preventing any single instance from becoming overwhelmed and for routing traffic away from any instances that become unresponsive.
The foundation for each EC2 instance is a Launch Template. This template defines the configuration for new instances, including the Amazon Machine Image (AMI), instance type, security groups, and storage. Crucially, it also incorporates User Data scripts. These scripts execute automatically when an instance launches, automating the setup process. In this project, User Data is used to install and configure the Apache web server and to generate a simple webpage. This webpage dynamically displays instance-specific information, such as the instance ID and Availability Zone, which is invaluable for verifying that traffic is indeed being routed to different instances across the environment.
The system's resilience was rigorously tested. This involved observing normal operation, simulating periods of high traffic to trigger scale-out events, and deliberately terminating instances to confirm that the Auto Scaling Group and ALB could automatically detect the failure, launch a replacement instance, and bring it back into service without significant user-facing disruption.

Core Components of High Availability
Application Load Balancer (ALB)
The ALB acts as the primary traffic manager. Unlike traditional load balancers, ALBs operate at the application layer (Layer 7), allowing for more intelligent routing decisions based on request content. For a highly available setup, the ALB is configured to be internet-facing and deployed across multiple Availability Zones. This ensures that if one AZ becomes unavailable, the ALB can still receive and route traffic from other available AZs. The ALB continuously monitors the health of registered targets (EC2 instances) through health checks defined in the Target Group. If an instance fails these health checks, the ALB stops sending traffic to it until it becomes healthy again. This immediate redirection of traffic away from unhealthy instances is a critical first line of defense against application downtime.
EC2 Instances and Launch Templates
The web application itself runs on Amazon EC2 instances. The configuration of these instances is standardized through Launch Templates. A Launch Template is a blueprint that specifies all the parameters needed to launch an EC2 instance, including the AMI, instance type, key pair, security groups, and block device mappings. Using a Launch Template ensures consistency across all instances launched by the Auto Scaling Group. The User Data script within the Launch Template is a powerful tool for automation. It allows administrators to pass scripts that are executed at launch time. This is ideal for bootstrapping applications, installing dependencies, and configuring the web server, ensuring that each new instance is ready to serve traffic immediately upon launch.
Auto Scaling Group (ASG)
The Auto Scaling Group is the workhorse of dynamic scaling and self-healing. It manages a collection of EC2 instances, ensuring that a desired number of instances are running and healthy. The ASG uses the Launch Template to launch new instances when needed. It also monitors the health of instances based on EC2 status checks and custom health checks defined via the ALB Target Group. When an instance is found to be unhealthy, the ASG automatically terminates it and launches a replacement instance, maintaining the desired capacity. Furthermore, ASGs can be configured with scaling policies. These policies allow the group to automatically adjust the number of instances based on metrics like CPU utilization, network traffic, or custom metrics. This ensures that the application can handle fluctuating traffic loads efficiently, scaling out during peak times and scaling in during lulls to optimize costs.
Multi-AZ Deployment
Deploying resources across multiple Availability Zones is fundamental to achieving high availability. An Availability Zone is one or more discrete data centers with redundant power, networking, and connectivity in an AWS Region. By deploying the ALB and EC2 instances across at least two AZs, the application can withstand the failure of an entire data center without experiencing downtime. The ALB automatically distributes traffic across instances in all healthy AZs, and the ASG ensures that instances are launched in AZs that have capacity, maintaining redundancy.
Self-Healing in Action
The self-healing aspect of this architecture is a direct benefit of the integration between the ALB, ASG, and EC2. When an EC2 instance experiences an issue—perhaps a software crash, a network problem, or an underlying hardware failure—it will eventually fail the health checks configured in the ALB's Target Group. Upon detecting this failure, the ALB immediately stops sending new requests to the affected instance. Concurrently, the ASG, which also monitors the health of its instances, registers the instance as unhealthy. The ASG then automatically terminates the faulty instance and initiates the launch of a new replacement instance using the defined Launch Template. As the new instance boots up, installs its software via User Data, and passes the ALB's health checks, it is gradually brought back into the pool of active targets. This process ensures that the application remains available to users with minimal interruption, as traffic is seamlessly rerouted and unhealthy components are automatically replaced.
Testing and Verification
To validate the architecture's effectiveness, several tests were performed:
- Normal Operation: Verified that the application is accessible via the ALB's DNS name and that the generated webpage displays correct instance information, showing traffic hitting different instances across AZs.
- Simulated Failure: Manually terminated an EC2 instance. Observed the ASG detecting the termination, launching a new instance, and the ALB registering the new instance as healthy after it passed health checks. User traffic was uninterrupted.
- Load Testing (Implied): While not detailed, the setup allows for load testing to verify that the Auto Scaling policies correctly trigger scale-out events under increased demand and scale-in events when demand subsides.
This comprehensive approach ensures that the web application is not only functional but also resilient, capable of automatically recovering from common failure scenarios and adapting to changing traffic demands.
