Skip to content

Sumeet-Y1/aws-autoscale-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ AWS Auto-Scale API

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.


πŸ—οΈ Architecture

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚              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)                        β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Tech Stack

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

πŸ“Š Load Test Results - 1000 Concurrent Users

k6 Load Test Results


  β–ˆ 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.


πŸ”₯ Key Features

⚑ Auto Scaling

  • 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

πŸ”„ Self Healing

  • ALB health checks hit /actuator/health every 30 seconds
  • Unhealthy instance? β†’ Automatically deregistered from ALB
  • ASG detects instance count drop β†’ Launches replacement automatically
  • Zero manual intervention required

πŸš€ Zero-Downtime Deployments

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Infrastructure (Terraform)

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 everything

Resources 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

πŸ”Œ API Endpoints

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

Sample Response - /api/hello

{
  "message": "Hello from AWS Auto-Scaling Infrastructure!",
  "server": "ip-10-0-1-245",
  "timestamp": "2026-06-03T14:32:11.123456",
  "status": "healthy"
}

The server field changes on each refresh proof the ALB is routing across multiple EC2 instances.


πŸ§ͺ Run Load Test

# Install k6
winget install k6

# Run 1000 user load test
k6 run -e ALB_URL=YOUR_ALB_DNS k6/loadtest.js

Test 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

πŸ”§ CI/CD Pipeline

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 βœ…

πŸ› οΈ Chaos Engineering - Self Healing Demo

  1. Go to AWS Console β†’ EC2 β†’ Instances
  2. Terminate any autoscale-ec2 instance manually
  3. Watch ASG detect the drop
  4. New instance launches automatically within 60 seconds
  5. Health checks pass β†’ Traffic resumes

The system heals itself. No alerts. No manual work.


βš™οΈ Setup & Deployment

Prerequisites

  • AWS CLI configured
  • Terraform installed
  • Docker installed
  • Java 21

Deploy

# 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 main

Destroy

cd terraform && terraform destroy

πŸ‘€ Author

Sumeet - GitHub

About

Self-healing AWS infrastructure 1000 concurrent users, 1268 req/s, 0% error rate. ALB + Auto Scaling + Terraform + GitHub Actions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors