<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: manoop madhu</title>
    <description>The latest articles on DEV Community by manoop madhu (@manoop_madhu).</description>
    <link>https://dev.to/manoop_madhu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3681976%2F6e7520f1-a657-4239-b76b-b8d0eb05c841.jpg</url>
      <title>DEV Community: manoop madhu</title>
      <link>https://dev.to/manoop_madhu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manoop_madhu"/>
    <language>en</language>
    <item>
      <title>Building a Production-Ready AWS ALB + Auto Scaling Architecture Using Terraform</title>
      <dc:creator>manoop madhu</dc:creator>
      <pubDate>Mon, 05 Jan 2026 06:34:04 +0000</pubDate>
      <link>https://dev.to/manoop_madhu/building-a-production-ready-aws-alb-auto-scaling-architecture-using-terraform-3nji</link>
      <guid>https://dev.to/manoop_madhu/building-a-production-ready-aws-alb-auto-scaling-architecture-using-terraform-3nji</guid>
      <description>&lt;p&gt;As part of my hands-on learning in AWS an&lt;br&gt;
 Terraform, I built a production-style web architecture that follows real-world cloud and DevOps best practices.&lt;/p&gt;

&lt;p&gt;Instead of exposing EC2 instances directly to the internet, this project uses an Application Load Balancer (ALB) in public subnets and Auto Scaling Group (ASG)–managed EC2 instances running in private subnets, with outbound internet access provided via a NAT Gateway.&lt;/p&gt;

&lt;p&gt;The entire infrastructure is provisioned using Terraform (Infrastructure as Code).&lt;/p&gt;

&lt;p&gt;🔗 GitHub Repository:&lt;br&gt;
&lt;a href="https://github.com/manoop98/terraform-aws-alb-asg-nginx" rel="noopener noreferrer"&gt;https://github.com/manoop98/terraform-aws-alb-asg-nginx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Architecture Overview&lt;br&gt;
High-level flow&lt;br&gt;
Internet&lt;br&gt;
   |&lt;br&gt;
Application Load Balancer (Public)&lt;br&gt;
   |&lt;br&gt;
Target Group (Port 8000)&lt;br&gt;
   |&lt;br&gt;
Auto Scaling Group&lt;br&gt;
   |&lt;br&gt;
EC2 Instances (Private Subnets)&lt;br&gt;
   |&lt;br&gt;
Docker + Nginx&lt;br&gt;
   |&lt;br&gt;
NAT Gateway (Outbound Internet)&lt;/p&gt;

&lt;p&gt;Key design principles&lt;/p&gt;

&lt;p&gt;✅ Only the ALB is public&lt;/p&gt;

&lt;p&gt;✅ EC2 instances live in private subnets&lt;/p&gt;

&lt;p&gt;✅ Auto Scaling Group ensures availability&lt;/p&gt;

&lt;p&gt;✅ NAT Gateway enables outbound access securely&lt;/p&gt;

&lt;p&gt;✅ Fully automated using Terraform&lt;/p&gt;

&lt;p&gt;This architecture closely mirrors what is commonly used in production AWS environments.&lt;/p&gt;

&lt;p&gt;Tech Stack&lt;/p&gt;

&lt;p&gt;AWS&lt;/p&gt;

&lt;p&gt;VPC&lt;/p&gt;

&lt;p&gt;EC2&lt;/p&gt;

&lt;p&gt;Application Load Balancer&lt;/p&gt;

&lt;p&gt;Auto Scaling Group&lt;/p&gt;

&lt;p&gt;Internet Gateway&lt;/p&gt;

&lt;p&gt;NAT Gateway&lt;/p&gt;

&lt;p&gt;Terraform – Infrastructure as Code&lt;/p&gt;

&lt;p&gt;Docker – Application runtime&lt;/p&gt;

&lt;p&gt;Nginx – Demo web server&lt;/p&gt;

&lt;p&gt;Project Structure&lt;br&gt;
terraform-aws-alb-asg-nginx/&lt;br&gt;
├── alb.tf&lt;br&gt;
├── asg.tf&lt;br&gt;
├── network.tf&lt;br&gt;
├── provider.tf&lt;br&gt;
├── security_groups.tf&lt;br&gt;
├── vpc.tf&lt;br&gt;
├── userdata.sh&lt;br&gt;
├── outputs.tf&lt;br&gt;
├── .gitignore&lt;br&gt;
└── README.md&lt;/p&gt;

&lt;p&gt;How It Works&lt;br&gt;
1️⃣ Networking Layer&lt;/p&gt;

&lt;p&gt;A custom VPC is created with:&lt;/p&gt;

&lt;p&gt;Two public subnets&lt;/p&gt;

&lt;p&gt;Two private subnets&lt;/p&gt;

&lt;p&gt;An Internet Gateway is attached to the VPC&lt;/p&gt;

&lt;p&gt;Public subnets route traffic to the Internet Gateway&lt;/p&gt;

&lt;p&gt;Private subnets route outbound traffic through a NAT Gateway&lt;/p&gt;

&lt;p&gt;2️⃣ Application Load Balancer&lt;/p&gt;

&lt;p&gt;The ALB is deployed in public subnets&lt;/p&gt;

&lt;p&gt;Listens on HTTP (port 80)&lt;/p&gt;

&lt;p&gt;Forwards traffic to a Target Group on port 8000&lt;/p&gt;

&lt;p&gt;3️⃣ Auto Scaling Group&lt;/p&gt;

&lt;p&gt;EC2 instances are launched using a Launch Template&lt;/p&gt;

&lt;p&gt;Instances are placed only in private subnets&lt;/p&gt;

&lt;p&gt;ASG automatically registers instances with the target group&lt;/p&gt;

&lt;p&gt;Health checks are handled by the ALB&lt;/p&gt;

&lt;p&gt;4️⃣ EC2 User Data &amp;amp; Application&lt;/p&gt;

&lt;p&gt;Each EC2 instance runs a simple Dockerized Nginx server using user data:&lt;/p&gt;

&lt;h1&gt;
  
  
  !/bin/bash
&lt;/h1&gt;

&lt;p&gt;yum update -y&lt;br&gt;
yum install docker -y&lt;br&gt;
systemctl start docker&lt;br&gt;
systemctl enable docker&lt;/p&gt;

&lt;p&gt;docker run -d -p 8000:80 nginx&lt;/p&gt;

&lt;p&gt;This ensures:&lt;/p&gt;

&lt;p&gt;Instances are ready immediately after launch&lt;/p&gt;

&lt;p&gt;Target group health checks pass&lt;/p&gt;

&lt;p&gt;ALB traffic works without manual intervention&lt;/p&gt;

&lt;p&gt;Key Challenges &amp;amp; Learnings&lt;/p&gt;

&lt;p&gt;This project was not just about writing Terraform — it involved real troubleshooting, which was the most valuable part.&lt;/p&gt;

&lt;p&gt;Some key learnings:&lt;/p&gt;

&lt;p&gt;AMI IDs are region-specific&lt;br&gt;
→ Solved by using a dynamic AMI data source&lt;/p&gt;

&lt;p&gt;ALB requires an Internet Gateway&lt;br&gt;
→ Public subnets must have a route to IGW&lt;/p&gt;

&lt;p&gt;Private EC2 instances need NAT Gateway&lt;br&gt;
→ Without NAT, Docker pulls and updates fail&lt;/p&gt;

&lt;p&gt;Not all Docker images serve content by default&lt;br&gt;
→ Switched to Nginx for predictable behavior&lt;/p&gt;

&lt;p&gt;Target group health checks are critical&lt;br&gt;
→ Correct ports and paths are essential&lt;/p&gt;

&lt;p&gt;These are the same challenges faced in real-world production environments.&lt;/p&gt;

&lt;p&gt;Final Result&lt;/p&gt;

&lt;p&gt;After terraform apply, the output provides an ALB DNS name.&lt;br&gt;
Opening it in a browser displays the Nginx welcome page, served from EC2 instances running in private subnets.&lt;/p&gt;

&lt;p&gt;✔ Secure&lt;br&gt;
✔ Scalable&lt;br&gt;
✔ Highly available&lt;br&gt;
✔ Fully automated&lt;/p&gt;

&lt;p&gt;Why This Project Matters&lt;/p&gt;

&lt;p&gt;This project helped me gain hands-on experience with:&lt;/p&gt;

&lt;p&gt;AWS networking fundamentals&lt;/p&gt;

&lt;p&gt;Secure cloud architecture design&lt;/p&gt;

&lt;p&gt;Auto Scaling and Load Balancing&lt;/p&gt;

&lt;p&gt;Terraform best practices&lt;/p&gt;

&lt;p&gt;Debugging real infrastructure issues&lt;/p&gt;

&lt;p&gt;It reflects how modern DevOps teams build and manage cloud infrastructure.&lt;/p&gt;

&lt;p&gt;Source Code&lt;/p&gt;

&lt;p&gt;🔗 GitHub Repository:&lt;br&gt;
&lt;a href="https://github.com/manoop98/terraform-aws-alb-asg-nginx" rel="noopener noreferrer"&gt;https://github.com/manoop98/terraform-aws-alb-asg-nginx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Building this project significantly improved my understanding of AWS infrastructure and Terraform.&lt;br&gt;
It reinforced the importance of security-first design, automation, and incremental validation.&lt;/p&gt;

&lt;p&gt;If you’re learning AWS or Terraform, I highly recommend building something similar — the lessons learned are invaluable.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;

&lt;h1&gt;
  
  
  terraform
&lt;/h1&gt;

&lt;h1&gt;
  
  
  aws
&lt;/h1&gt;

&lt;h1&gt;
  
  
  devops
&lt;/h1&gt;

&lt;h1&gt;
  
  
  cloud
&lt;/h1&gt;

&lt;h1&gt;
  
  
  infrastructureascode
&lt;/h1&gt;

</description>
      <category>architecture</category>
      <category>aws</category>
      <category>devops</category>
      <category>terraform</category>
    </item>
  </channel>
</rss>
