Self-healing, load-balanced website on AWS using EC2 + ALB with zero-downtime failover.
This project demonstrates a fault-tolerant, load-balanced web application deployed entirely on AWS. I deployed a static HTML website across two EC2 instances and placed an Application Load Balancer (ALB) in front of them to distribute traffic automatically.
The Challenge: Build a system where if one server crashes, the website still works without any manual intervention.
User (Browser) │ ▼ Application Load Balancer (web-alb) │ ▼ Target Group (my-web-tg) │ ├──────► EC2 Instance 1 (My-Web-Server-1) [ap-south-1a] │ ├─ Instance ID: i-0804d82a9146e284f │ └─ Private IP: 172.31.x.x │ └──────► EC2 Instance 2 (My-Web-Server-2) [ap-south-1b] ├─ Instance ID: i-0e3a7617b6623f145 └─ Private IP: 172.31.0.35
- Compute: AWS EC2 (Amazon Linux 2023,
t2.micro) - Web Server: Apache (httpd)
- Load Balancing: AWS Application Load Balancer (Layer 7)
- Networking: VPC, Subnets (Multi-AZ), Security Groups
- Automation: User-data bash scripts for bootstrap configuration
- Metadata: IMDSv2 (Instance Metadata Service v2) for dynamic IP/ID retrieval
- Monitoring: Target Group Health Checks
- Zero-Config Automation: Used EC2 User Data to automatically install Apache and deploy the HTML page—zero manual SSH setup required for initial deployment.
- Dynamic Identification: Each EC2 instance queries the AWS Metadata Service (IMDSv2) to display its unique Instance ID and Private IP directly on the webpage.
- Traffic Distribution: The ALB uses a Round-Robin algorithm to split incoming requests between the 2 instances.
- Self-Healing (Health Checks): Configured Target Group Health Checks (HTTP:80). When an instance fails, it is automatically detached from the rotation.
- Action: Refreshed the ALB DNS name.
- Result: The page alternated between "Hello from Server 1" and "Hello from Server 2".
- Screenshot:
[Paste Screenshot showing alternating Server 1 / Server 2 here]
- Action: Manually stopped
My-Web-Server-1via the AWS Console. - Result: The Target Group health check immediately flagged it as
Unhealthy. The ALB routed 100% of the traffic toServer 2. Zero downtime experienced by the end-user. - Screenshot:
[Paste Screenshot of Target Group showing one Unhealthy here]
- Action: Restarted (resumed) the stopped instance.
- Result: After 60 seconds, the Target Group automatically marked it as
Healthyagain and the ALB resumed sending traffic to both servers.
- IMDSv2 vs IMDSv1: How to securely fetch instance metadata using a PUT request token.
- Importance of AZs (Availability Zones): Deploying instances across
ap-south-1aandap-south-1bprotects against a single data center failure. - The Power of Health Checks: Infrastructure can be self-healing if you configure it correctly; you don't need to wake up at 3 AM to reboot a server.
- Launch 2 Amazon Linux 2023 EC2 instances with a Security Group allowing HTTP (80) and SSH (22).
- Paste the provided User-Data script during launch.
- Create a Target Group and register both instances.
- Create an Internet-facing ALB and attach the Target Group.
- Access the ALB DNS name in your browser!