Production-grade, self-healing infrastructure that handles 1000 concurrent users at 1,268 req/s with zero errors - fully automated from git push to live deployment.
βββββββββββββββββββββββββββββββββββββββββββ
β GitHub Actions β
β push β build β dockerize β ECR push β
β β ASG Instance Refresh β
ββββββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββΌβββββββ
β AWS ECR β
βDocker Imagesβ
ββββββββ¬βββββββ
β
βββββββββββββββββββββββββββββββββ βΌ βββββββββββββββββββββββββββββββββ
β AWS VPC (ap-south-1) β
β β
β βββββββββββββββββββββββββββββββββββββββ β
β β Application Load Balancer (ALB) β β HTTP :80 β
β ββββββββββββ¬βββββββββββββββ¬ββββββββββββ β
β β β β
β ββββββββββββΌβββ ββββββΌβββββββββ β
β β EC2 :8080 β β EC2 :8080 β β Auto Scaling β
β β ap-south-1a β β ap-south-1b β Group (2-6) β
β βββββββββββββββ βββββββββββββββ β
β β
β CloudWatch β CPU > 50% β Scale Up (+2) β
β CloudWatch β CPU < 20% β Scale Down (-1) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Layer | Technology |
|---|---|
| Application | Spring Boot 3.5, Java 21 |
| Containerization | Docker, AWS ECR |
| Infrastructure | Terraform, AWS VPC, Subnets, IGW |
| Compute | AWS EC2 (m7i-flex.large), Auto Scaling Group |
| Load Balancing | AWS Application Load Balancer |
| CI/CD | GitHub Actions |
| Monitoring | AWS CloudWatch, Prometheus, Actuator |
| Load Testing | k6 |
| OS | Ubuntu 22.04 LTS |
β THRESHOLDS
errors β rate=0.00%
http_req_duration β p(95)=56.67ms
β TOTAL RESULTS
Total Requests......: 229,074
Requests/sec........: 1,268 req/s π
Error Rate..........: 0.00% β
Avg Response Time...: 38.24ms β‘
P95 Response Time...: 56.67ms β‘
Data Received.......: 77 MB
Duration............: 3 minutes
Max VUs.............: 1,000
229K requests. Zero errors. 38ms average response. 1000 users. Infrastructure auto-scaled and self-healed throughout.
- Minimum 2 EC2 instances always running across 2 Availability Zones
- Scales up by +2 instances when CPU > 50%
- Scales down by -1 instance when CPU < 20%
- Maximum 6 instances at peak load
- ALB health checks hit
/actuator/healthevery 30 seconds - Unhealthy instance? β Automatically deregistered from ALB
- ASG detects instance count drop β Launches replacement automatically
- Zero manual intervention required
- Git push β GitHub Actions triggers
- New Docker image built and pushed to ECR
- ASG Instance Refresh with
MinHealthyPercentage=50 - Rolling update - old instances drain, new ones warm up
aws-autoscale-api/
βββ src/
β βββ main/java/com/devops/aws_autoscale_api/
β βββ AwsAutoscaleApiApplication.java
β βββ AppController.java
βββ terraform/
β βββ main.tf # Complete AWS infrastructure as code
βββ k6/
β βββ loadtest.js # 1000 user load test script
βββ .github/
β βββ workflows/
β βββ deploy.yml # CI/CD pipeline
βββ Dockerfile
Everything provisioned as code one command to create, one command to destroy:
cd terraform
terraform init
terraform apply # provisions everything in ~5 minutes
terraform destroy # tears down everythingResources provisioned (22 total):
- VPC + 2 Public Subnets (ap-south-1a, ap-south-1b)
- Internet Gateway + Route Tables
- Security Groups (ALB + EC2)
- Application Load Balancer + Target Group + Listener
- Launch Template (Ubuntu 22.04, m7i-flex.large, 20GB gp3)
- Auto Scaling Group (min: 2, max: 6)
- CloudWatch Alarms (high CPU + low CPU)
- Auto Scaling Policies (scale up + scale down)
- ECR Repository
- IAM Role + Instance Profile
| Endpoint | Description |
|---|---|
GET /api/hello |
Returns server hostname + timestamp |
GET /api/info |
Returns CPU, memory, server stats |
GET /actuator/health |
Health check (used by ALB) |
GET /actuator/prometheus |
Prometheus metrics |
{
"message": "Hello from AWS Auto-Scaling Infrastructure!",
"server": "ip-10-0-1-245",
"timestamp": "2026-06-03T14:32:11.123456",
"status": "healthy"
}The
serverfield changes on each refresh proof the ALB is routing across multiple EC2 instances.
# Install k6
winget install k6
# Run 1000 user load test
k6 run -e ALB_URL=YOUR_ALB_DNS k6/loadtest.jsTest stages:
0:00 β 0:30 β ramp up to 100 users
0:30 β 1:30 β ramp up to 500 users
1:30 β 2:30 β ramp up to 1000 users β ASG scales here
2:30 β 3:00 β ramp down to 0
git push origin main
β
βΌ
GitHub Actions
β
βββ Build JAR (Maven)
βββ Build Docker Image
βββ Push to AWS ECR (:latest + :commit-sha)
βββ Trigger ASG Instance Refresh
β
βΌ
Rolling deployment
Zero downtime β
- Go to AWS Console β EC2 β Instances
- Terminate any
autoscale-ec2instance manually - Watch ASG detect the drop
- New instance launches automatically within 60 seconds
- Health checks pass β Traffic resumes
The system heals itself. No alerts. No manual work.
- AWS CLI configured
- Terraform installed
- Docker installed
- Java 21
# 1. Clone
git clone https://github.com/Sumeet-Y1/aws-autoscale-api
# 2. Provision infrastructure
cd terraform && terraform apply
# 3. Push Docker image to ECR
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.ap-south-1.amazonaws.com
docker build -t aws-autoscale-api .
docker tag aws-autoscale-api:latest ECR_URL:latest
docker push ECR_URL:latest
# 4. Push to GitHub β CI/CD auto-deploys
git push origin maincd terraform && terraform destroySumeet - GitHub
