DEV Community

Cover image for 🧭 Stop Hardcoding IPs! Discover Services the Right Way with AWS Cloud Map + ECS + Terraform

🧭 Stop Hardcoding IPs! Discover Services the Right Way with AWS Cloud Map + ECS + Terraform

Tired of hardcoding IPs between microservices?

Still slapping load balancers everywhere just to get containers to talk?

You're not alone — and you're definitely not doing it wrong...

But there is a smarter, cleaner, more scalable way.

🎯 Enter AWS Cloud Map — your secret weapon for service discovery in modern containerized apps.


🛠️ What We’re Building (With Zero Hand-Wiring)

In this hands-on guide, we’ll build a fully working ECS setup using Terraform, where:

✅ An NGINX container runs on ECS Fargate

✅ It auto-registers with AWS Cloud Map

✅ Other services can just call it by name — like backend.myapp.local

✅ No IP hardcoding. No messy scripts. No manual DNS configs.

Think: Dynamic, scalable service discovery — baked into your architecture.

And along the way, I’ll explain the “why” behind every AWS service we touch — not just “what it does”, but “why it matters” for microservices and DevOps sanity.


⚡ TL;DR — Our Smart, IP-Free Stack

  • 🐳 ECS Fargate – Run containers serverlessly
  • 🧭 Cloud Map – Register services with DNS
  • 🌐 Private DNS Namespace – Internal routing made easy
  • 🔐 IAM Roles – Least privilege for ECS tasks
  • 🧱 Terraform – Infrastructure as clean, versioned code

🧠 Why Hardcoding IPs is a DevOps Trap

Let’s face it — containers are ephemeral.

One moment they’re alive… the next, boom 💥 — redeployed or gone.

Still managing hostnames manually? That’s fragile, error-prone, and just not scalable.

Scenario Without Cloud Map With Cloud Map
Task restarts Frontend breaks 😖 Frontend still resolves 🎯
Scaling services Manual DNS updates 😩 Auto-updates 🛠️
Load balancing Complex config 😵 DNS handles it 💡

Bottom line: AWS Cloud Map + ECS = automatic, seamless, resilient microservice communication.


🧰 Stack Breakdown – What’s in the Toolbox?

📦 Amazon ECS (with Fargate)

Forget EC2s. Let AWS handle infra — just define CPU + memory and go.

cpu    = "256"
memory = "512"
Enter fullscreen mode Exit fullscreen mode

and boom — it runs your container.

📦 AWS Cloud Map

This is the star of the show. Cloud Map lets your services register themselves with a name, like backend.myapp.local, and updates DNS records as services start/stop.

Two ways to discover:

  • DNS (via Route 53) — simple and fast
  • API-based lookup — flexible and metadata-driven

📦 Private DNS Namespace

Think of this like a private Route 53 zone — but attached to your VPC. Only resources inside the VPC can resolve names like backend.myapp.local.

📦 AWS IAM Role for ECS

This role gives your ECS task permission to:

  • Pull container images
  • Write logs to CloudWatch
  • Register with Cloud Map

📦 Terraform

Terraform is our Infrastructure-as-Code (IaC) tool. With it, we can version, share, and automate our entire cloud infrastructure.

  • No more point-and-click hell.
  • Just clean .tf files, reusable modules, and version-controlled deployments.
  • Infrastructure-as-Code, the way it should be.

🎉 Ready to Build?

In the next section, we’ll dive into the actual Terraform code, wire up all these AWS services, and get dynamic service discovery running on ECS — no manual IPs, no chaos.

Let’s go from hardcoded hacks ➡️ to clean, discoverable microservices.

Top comments (0)