The Problem
Running separate Application Load Balancers (ALBs) for each application costs $16-18/month per ALB. With 5 apps, that's $80-90/month just for load balancers.
The Solution
Use a single ALB with path-based or host-based routing rules to serve multiple applications, reducing costs by up to 80%.
Step 1: Create One Application Load Balancer
Go to EC2 > Load Balancers in AWS Console
Click Create Load Balancer > Application Load Balancer
Configure:
Name: shared-alb
Scheme: Internet-facing
IP address type: IPv4
Select at least 2 availability zones
Configure security group (allow HTTP/HTTPS)
Create the ALB
Step 2: Create Target Groups for Each App
For each application, create a separate target group:
Go to EC2 > Target Groups
Click Create target group
Configure each:
Target type: Instances/IP/Lambda (based on your setup)
Name: app1-targets, app2-targets, etc.
Protocol: HTTP
Port: Your app's port
Health check path: /health or /
Register targets (EC2 instances, containers, IPs)
Step 3: Set Up Routing Rules
Option A: Path-Based Routing (Same domain, different paths)
Go to your ALB > Listeners tab
Select HTTP:80 or HTTPS:443 listener
Click Manage rules > Add rules
Create rules for each app:
Rule 1: /app1* → Forward to app1-targets
Rule 2: /app2* → Forward to app2-targets
Rule 3: /api/* → Forward to api-targets
Default: Forward to landing-page-targets
Option B: Host-Based Routing (Different subdomains)
Create rules based on hostname:
Rule 1: app1.example.com → Forward to app1-targets
Rule 2: app2.example.com → Forward to app2-targets
Rule 3: api.example.com → Forward to api-targets
Step 4: Configure DNS
Point all domains/subdomains to the single ALB:
Route 53 or your DNS provider:
app1.example.com → CNAME → shared-alb-xxxxx.region.elb.amazonaws.com
app2.example.com → CNAME → shared-alb-xxxxx.region.elb.amazonaws.com
api.example.com → CNAME → shared-alb-xxxxx.region.elb.amazonaws.com
Step 5: Add SSL Certificates (Optional but Recommended)
Request certificates in AWS Certificate Manager for all domains
Add certificates to ALB listener (HTTPS:443)
Step 6: Configure Health Checks
For each target group:
Go to Target Groups > Select group
Edit Health check settings:
Path: /health or your health endpoint
Interval: 30 seconds
Timeout: 5 seconds
Healthy threshold: 2
Unhealthy threshold: 3
Cost Savings Example
Before (5 separate ALBs):
5 ALBs × $16/month = $80/month
Total: $80/month
After (1 shared ALB):
1 ALB × $16/month = $16/month
Total: $16/month
Savings: $64/month ($768/year)
Best Practices
Use Priority Rules Wisely - More specific rules should have lower priority numbers
Monitor Target Health - Set up CloudWatch alarms for unhealthy targets
Enable Access Logs - Store in S3 for troubleshooting
Use HTTPS - Terminate SSL at ALB for better security
Set Appropriate Timeouts - Match your app's response times
Tag Everything - Tag target groups and ALB for cost tracking
Limitations to Consider
ALB has limits (100 rules per listener, 50 targets per target group by default)
All apps share the same ALB capacity (but auto-scales)
Request limits apply to the entire ALB, not per app
One ALB failure affects all applications (use multiple ALBs across regions for critical apps)
When NOT to Use This Approach
- Regulatory requirements mandate isolation
- Apps have drastically different traffic patterns
- You need different network configurations per app
- Critical production apps requiring dedicated resources
Conclusion
Using a single ALB with routing rules is a simple yet powerful way to reduce AWS costs without sacrificing functionality. For most small to medium workloads, this approach provides excellent cost optimization while maintaining flexibility and scalability.
Top comments (0)