DEV Community

Cover image for Building Scalable Web Apps on AWS: My Hands-On Journey with ALBs, ASGs, and Custom VPCs
Deepak Soni
Deepak Soni

Posted on

Building Scalable Web Apps on AWS: My Hands-On Journey with ALBs, ASGs, and Custom VPCs

Posted at 5 AM, after another late-night deep dive into the cloud.

After learning from a painful mistake last night (read my previous post if you're curious), I promised myself to rebuild everything from scratch today, this time the right way.

And I did. I combined my learnings from the past two days: Application Load Balancers and Auto Scaling Groups into one working mini project.

πŸ› οΈ What I Built

To keep it structured, here’s what the setup looked like:

  • VPC Setup: Created a custom VPC with 3 public and 3 private subnets (spread across multiple Availability Zones for high availability).

  • Internet & NAT Gateways:

    • Attached an Internet Gateway (IGW) to allow public access to public subnets.
    • Deployed one NAT Gateway per public subnet to route internet traffic for the private subnets securely.
  • Routing & Security:

    • Created Route Tables and associated them with respective subnets.
    • Configured Security Groups for public-facing and internal components.
  • Flask App & Launch Template:

    • Set up a simple Flask server running on port 8080.
    • Created a custom AMI from this EC2 instance.
    • Used it to define an EC2 Launch Template.
  • Target Group & Load Balancer:

    • Created a Target Group pointing to instances in the private subnets on port 8080.
    • Deployed an Application Load Balancer (ALB) in the public subnets and connected it to the target group.
  • Auto Scaling Group (ASG):

    • Configured the ASG using the launch template and attached it to the target group.
    • This enabled instances to scale in and out automatically based on demand.
  • Bastion Host for Debugging:

    • Deployed a Bastion EC2 instance in a public subnet with a public IP.
    • Used it to SSH into the private EC2 instances for validation and debugging.

βœ… Final Result

The Application Load Balancer started successfully routing traffic to EC2 instances launched by the Auto Scaling Group. Each response was coming from a different instance depending on the load, a satisfying sight after a night of building.

πŸŒ™ Reflection

Compared to yesterday, this build felt cleaner and more intentional. Every service was tested step-by-step before stitching them together. A reminder that in the cloud (and in life), skipping fundamentals can cost you time, but every mistake brings clarity.

πŸ“Œ Tech Stack

  • AWS EC2, VPC, IGW, NAT Gateway
  • Application Load Balancer (ALB)
  • Auto Scaling Groups (ASG)
  • Flask (Python)
  • Custom AMIs & Launch Templates

πŸ’¬ Let’s Connect

Have you tried setting up ASGs + ALBs from scratch before? Got tips for a smoother setup or common pitfalls? Let’s chat in the comments!

Top comments (0)