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)