DEV Community

Cover image for Stop Wrestling with AWS: I Built a Tool to Generate Production-Ready Node.js & Terraform
Pau Dang
Pau Dang

Posted on

Stop Wrestling with AWS: I Built a Tool to Generate Production-Ready Node.js & Terraform

A deep dive into how I automated setting up Node.js backends and AWS infrastructure using Terraform.

If you’re anything like me, starting a new project is the most exciting part of development. You get to choose your architecture, set up your folders, and start writing code.

But then comes the deployment phase...

Suddenly, you're wrestling with the AWS Console. You need a VPC, public/private subnets, an Internet Gateway, Route Tables, NAT Gateways, Security Groups, an ALB, EC2 instances, and an RDS database.

It takes hours, and if you miss a single route table entry, nothing works.

I got tired of repeating this painful process. So, I decided to solve it. I built a CLI tool that not only generates a robust Node.js backend (Clean Architecture, TypeScript, etc.) but also includes production-ready AWS infrastructure as code (IaC) using Terraform.

Here is how it works, and how you can use it to spin up an AWS environment locally for free.


The "Everything is a Click" Problem

ClickOps (configuring infrastructure manually via the AWS UI) is fine for learning, but terrible for repeatability. If you want to replicate a setup or tear it down, you have to click through 20 different screens.

With Node.js Quickstart Structure, you can generate a complete backend with the infrastructure already wired up:

npx nodejs-quickstart-structure@latest init -n "nodejs-service" -l "TypeScript" -a "Clean Architecture" -d "MySQL" --db-name "demo" -c "REST APIs" --caching "None" --ci-provider "GitHub Actions" --auth None --terraform "Production" --no-include-security --advanced-options
Enter fullscreen mode Exit fullscreen mode

( Pro tip: Insert a cool GIF or screenshot of your CLI running here!)

The CLI asks you a few questions (TypeScript? Clean Architecture? Postgres?) and then creates a complete repository. But the real magic happens in the terraform/ folder.

Two Flavors of Infrastructure (Because Cost Matters)

Not every project is a massive enterprise app. Side projects need to be cheap, while production apps need to be highly available. I designed two Terraform templates to match these needs:

1. Standard Tier (The "Keep it Cheap" Setup)

Perfect for side projects, MVPs, and dev environments.

  • Single EC2 instance
  • Single-AZ RDS database
  • Shared NAT Gateway

Goal: Keep your AWS bill under $30/month (or even within the Free Tier).

Snippet of what gets generated:

module "ec2" {
  source        = "./modules/ec2"
  instance_type = "t3.micro"
  # ... automatically wired to your VPC and DB
}
Enter fullscreen mode Exit fullscreen mode

2. Production Tier (High Availability)

When you're ready for the big leagues. This tier provisions:

  • Multi-AZ Architecture for zero-downtime failover.
  • Application Load Balancer (ALB) to distribute traffic smoothly.
  • AWS WAF (Web Application Firewall) to block SQLi and XSS automatically.
  • Air-gapped RDS in isolated subnets for maximum security.

The Best Part: Testing Locally for FREE with LocalStack

I know what you're thinking: "Terraform is great, but running terraform apply on AWS costs money. How do I test this without going broke?"

This was a major pain point, so I integrated LocalStack support right out of the box. You can spin up the entire AWS architecture on your local machine using Docker—completely free. Setup Local Testing

Just start LocalStack:

localstack start -d
Enter fullscreen mode Exit fullscreen mode

Create a localstack.tf file to point Terraform to your local machine:

provider "aws" {
  region                      = "us-east-1"
  access_key                  = "test"
  secret_key                  = "test"
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  skip_metadata_api_check     = true
  s3_use_path_style           = true

  endpoints {
    ec2 = "http://localhost:4566"
    rds = "http://localhost:4566"
    # ...
  }
}
Enter fullscreen mode Exit fullscreen mode

And run:

terraform apply -auto-approve
Enter fullscreen mode Exit fullscreen mode

Boom. You now have a local VPC, EC2 instance, and RDS database running on your laptop. You can validate your entire infrastructure setup without giving Amazon your credit card.

Try it out!

I built this tool to save developers time and enforce best practices from day one. Whether you're building a quick weekend hackathon project or a serious enterprise application, the foundation is ready for you.

Give it a spin, and let me know what you think!

👉 Nodejs Quickstart Generator
👉 How to use the tool and video demo
👉 Sample Project: nodejs-service-terraform

If this saves you a few hours of AWS headaches, dropping a ⭐ on the repo would mean the world to me. I'd love to hear your feedback in the comments!

Top comments (0)