This project demonstrates a scalable and highly available AWS web application architecture running on private EC2 instances behind an Application Load Balancer.
The application focuses on infrastructure architecture, immutable deployment concepts, Auto Scaling, and secure cloud networking rather than complex business logic.
The frontend dynamically displays live EC2 instance metadata such as Instance ID, Availability Zone, and Hostname, demonstrating real-time load balancing and Auto Scaling behavior across multiple instances.
The infrastructure uses a stateless deployment model where new EC2 instances automatically bootstrap themselves using Launch Template User Data, GitHub source control, PM2 process management, and dependency installation during instance launch.
π https://app.tribhuvansharma.com (not live now because of costs, can be made so upon request)
This architecture demonstrates immutable infrastructure deployment principles using Auto Scaling Groups, Launch Template bootstrapping, private EC2 instances, NAT Gateway outbound access, and IMDSv2-secured EC2 metadata retrieval.
| Service | Purpose |
|---|---|
| Amazon EC2 | Application hosting |
| Auto Scaling Group | Horizontal scaling & self-healing |
| Application Load Balancer | Traffic distribution |
| Amazon VPC | Network isolation |
| Public & Private Subnets | Secure network segmentation |
| NAT Gateway | Outbound internet access for private instances |
| Internet Gateway | Public internet connectivity |
| Route 53 | DNS routing |
| AWS Systems Manager (SSM) | Secure instance management |
| Amazon CloudWatch | Monitoring & Auto Scaling alarms |
| PM2 | Node.js process management |
| Node.js + Express | Web application runtime |
| GitHub | Source control |
- Highly available AWS web application architecture
- Application Load Balancer distributing traffic across multiple EC2 instances
- Auto Scaling Group spanning multiple Availability Zones
- Private EC2 deployment with no public SSH access
- Stateless / immutable deployment model using Launch Template User Data
- Dynamic infrastructure dashboard displaying live EC2 metadata
- Real-time display of:
- EC2 Instance ID
- Availability Zone
- Hostname
- IMDSv2-secured metadata retrieval
- NAT Gateway outbound internet access for package installation and GitHub repository cloning
- PM2 process management for application resiliency
- CloudWatch-based Auto Scaling policies
- Secure network segmentation using public and private subnets
- Route 53 custom domain integration
- HTTPS-enabled application delivery
- GitHub-based source control and deployment workflow
- Self-healing infrastructure through Auto Scaling instance replacement
- Security Group-based least-privilege access controls
- Systems Manager (SSM) used instead of public SSH access
- Infrastructure-focused architecture demonstrating real-world AWS design patterns
This architecture uses a secure VPC setup:
-
Public Subnet:
- Application Load Balancer
- NAT Gateway
-
Private Subnet:
- EC2 Instances (no public IP)
- Enables communication between VPC and the internet
- Attached to the VPC
- Used by ALB (public access)
- Placed in public subnet
- Allows private EC2 instances to:
- Pull code from GitHub
- Install packages
- Prevents inbound internet access
| Subnet Type | Route Configuration |
|---|---|
| Public Subnet | 0.0.0.0/0 β Internet Gateway |
| Private Subnet | 0.0.0.0/0 β NAT Gateway |
- User accesses the application via Route 53
- Traffic is routed to the Application Load Balancer (ALB)
- ALB distributes requests across private EC2 instances in multiple Availability Zones
- EC2 instances serve the Node.js application running on port 3000
- The application dynamically retrieves EC2 metadata using IMDSv2
- Auto Scaling Groups manage instance scaling and replacement
- NAT Gateway provides outbound internet access for package installation and GitHub repository cloning
- CloudWatch monitors infrastructure metrics and triggers scaling policies
This project implements a stateless deployment architecture.
Each EC2 instance on launch:
- Installs dependencies (Node.js, PM2)
- Pulls latest code from GitHub
- Starts the application automatically
| Before | After |
|---|---|
| Manual SSH deployments | Automated via User Data |
| Stateful instances | Stateless infrastructure |
| Inconsistent deployments | Fully reproducible |
- Trigger: CPU > 60%
- Action: Add instances
- Trigger: CPU < 42%
- Action: Remove instances
- ALB performs health checks
- Unhealthy instances replaced automatically by ASG
- Ensures high availability
| Component | Access |
|---|---|
| EC2 Instances | β No public access |
| ALB | β Public (HTTPS only) |
| EC2 Port 3000 | β Only from ALB |
| SSH | β Disabled |
- SSH completely removed
- AWS Systems Manager (SSM) used for access
- IAM role with least privilege
- IMDSv2 enforced for secure metadata access
- Reduced attack surface
- No exposed ports
- Secure, auditable access
-
CloudWatch Metrics:
-
CPU Utilization
-
Instance health
-
CloudWatch Alarms:
-
High CPU β Scale Out
-
Low CPU β Scale In
for i in {1..20}; do curl -s https://app.tribhuvansharma.com; done
The test was used to validate:
- Application Load Balancer traffic distribution
- Auto Scaling Group instance availability
- Stateless application behavior
- Dynamic EC2 metadata retrieval
- Immutable deployment consistency across instances
Repeated requests returned dynamically changing infrastructure metadata depending on which EC2 instance served the request.
Validated fields included:
- EC2 Instance ID
- Availability Zone
- Hostname
Example observations:
Instance ID:
i-xxxxxxxxxxxxx
Availability Zone:
eu-central-1a
and
Instance ID:
i-yyyyyyyyyyyyy
Availability Zone:
eu-central-1b
This demonstrated successful ALB request routing across multiple Auto Scaling Group instances while maintaining consistent application behavior.
The application successfully retrieved EC2 metadata using IMDSv2 token-based authentication, validating secure metadata access configuration on dynamically provisioned EC2 instances.
| Test | Result |
|---|---|
| Direct EC2 access | β Blocked |
| SSH access | β Disabled |
| ALB access | β Allowed |
| SSM access | β Allowed |
- Removed bastion host
- Auto scaling prevents over-provisioning
- Efficient resource usage via stateless design
The project evolved from an earlier SSH/bastion-based deployment model into a fully stateless infrastructure design.
Current deployment flow:
Launch Template User Data β Install dependencies β Clone GitHub repository β Install Node.js packages β Start application using PM2
New EC2 instances are automatically provisioned and configured during Auto Scaling events without requiring manual SSH access or server-specific configuration.
This approach follows modern cloud infrastructure best practices often referred to as:
- Immutable Infrastructure
- Cattle not Pets
- Stateless Deployments
The application retrieves live EC2 instance metadata such as:
- Instance ID
- Availability Zone
- Hostname
using the EC2 Instance Metadata Service Version 2 (IMDSv2).
IMDSv2 improves security by requiring temporary session tokens for metadata access instead of unauthenticated metadata requests.
- Designing scalable AWS architectures
- Implementing stateless infrastructure
- Replacing SSH with SSM
- Auto scaling using CloudWatch metrics
- Debugging multi-instance inconsistencies
- Applying least-privilege security
- Designing immutable infrastructure deployments
- Building highly available Multi-AZ architectures
- Using Launch Template User Data for stateless provisioning
- Implementing IMDSv2-secured metadata retrieval
- Auto Scaling Group instance refresh workflows
- Real-world cloud debugging and operational troubleshooting
- Port conflicts from multiple Node processes
- Inconsistent responses across instances
- SSH-based deployment limitations
- Security group misconfigurations
- Load balancer routing issues
- Transitioning to stateless architecture
- Migrating from mutable SSH deployments to immutable infrastructure
- Handling stale Node.js processes across instance replacements
- Debugging PM2 startup persistence
- Implementing dependency installation during bootstrapping
- Troubleshooting IMDSv2 metadata access failures
- Managing Auto Scaling Group rolling refresh behavior
- Blue/Green deployment strategy
- Docker + ECS/Fargate
- Infrastructure as Code (Terraform)
- Advanced monitoring dashboards
- CI/CD pipeline without SSH
- Containerize application using Docker
- Migrate deployment to ECS Fargate
- Introduce Infrastructure as Code using Terraform
- Add CI/CD pipeline using GitHub Actions
- Add centralized logging aggregation
- Introduce blue/green deployment strategy
aws-webapp-pvt-ec2/
β
βββ app.js
βββ deploy.sh
βββ architecture.png
βββ README.md
Tribhuvan Sharma
AWS Certified Solutions Architect
Aspiring Solutions Consultant / Pre-Sales Engineer

