Register namespace in Cloud Map

Overview

In our upcoming steps, we will deploy the Frontend and Backend applications into separate Amazon ECS Services running on AWS Fargate.

However, because containers can be stopped, restarted, or scaled horizontally across multiple Availability Zones, their private IP addresses change dynamically. If the Frontend hardcodes the Backend’s private IP, any container replacement or scaling event will cause connection failures.

To solve this challenge, AWS provides AWS Cloud Map, a fully managed cloud resource discovery service:

  • Service Registry: Keeps track of dynamic endpoints (IP addresses, ports, and URLs) for each running service.
  • Dynamic DNS Resolution: Cloud Map integrates with Amazon Route 53 to create a private hosted zone inside your VPC.
  • Automatic Registration: When ECS launches or stops Backend tasks, it automatically registers and deregisters their private IP addresses in Cloud Map.
  • Simplified Inter-Service Communication: The Frontend service can simply connect to a domain name (backend.FCAJResbar.internal) without worrying about underlying IP changes.

How does Service Discovery work between ECS and Cloud Map? When a namespace is created with API calls and DNS queries in VPCs, AWS Cloud Map automatically provisions an Amazon Route 53 Private Hosted Zone linked to your VPC. When ECS launches a task for your Backend service, it automatically registers the container’s private IP into this DNS record. The Frontend container queries standard VPC DNS (Route 53 Resolver) and receives the current healthy Backend IP.


Step 1: Navigate to AWS Cloud Map Console

  1. Sign in to the AWS Management Console.
  2. Make sure you are in the same AWS Region where you created your VPC in Step 2 (us-east-1 N. Virginia)

Always verify the AWS Region in the top-right corner of the AWS Console. Cloud Map namespaces and Route 53 Private Hosted Zones are region-bound to the VPC. If you create the namespace in a different region than your VPC, your ECS tasks won’t be able to discover each other!

  1. In the top search bar, type Cloud Map and select Cloud Map from the services list.

4.1


Step 2: Create a Private Namespace

A Namespace in Cloud Map defines the boundary and domain structure for your microservices (similar to a top-level private domain name).

  1. In the left navigation pane or on the Cloud Map welcome screen, select Namespaces.
  2. Click the Create namespace button on the right.

4.2

  1. In the Namespace configuration section, provide the following parameters:
Field Value Description
Namespace name FCAJResbar.internal The root domain name for all services within this namespace.
Description Use for internal API Calls and DNS An optional description indicating the purpose of this namespace.
Instance discovery API calls and DNS queries in VPCs Enables standard DNS lookups within your VPC via Route 53 private hosted zones.

4.3

API calls only requires application code to call AWS Cloud Map SDK/APIs to discover IP addresses. API calls and DNS queries in VPCs automatically creates a Route 53 Private Hosted Zone. Applications can use standard HTTP requests like http://backend.FCAJResbar.internal:3000 without any AWS SDK dependencies in the codebase.

  1. Under the DNS configuration section:
    • VPC: Select FCAJ-Lab-vpc
    • TTL (Time to live): Enter 20 seconds.

Understanding TTL (Time To Live):
TTL dictates how long DNS resolvers inside your VPC cache the DNS response. A low TTL like 20 seconds is ideal for containerized environments because when tasks are replaced or scaled, clients quickly receive the updated IP addresses without waiting for stale cache to expire.

  1. Click Create namespace.

4.4

  1. Wait a few moments. Once the deployment finishes, the status will show Success.

4.5


Step 3: Create a Service in the Namespace

Next, we define a Service within our namespace. A service represents a specific component (such as our Backend API) and defines how its instances are registered and routed.

  1. On the namespace details page for FCAJResbar.internal, scroll down to the Services section.
  2. Click Create service.

4.6

  1. On the Service configuration page, fill in the service details:
Field Value Explanation
Service name backend The prefix for the service. When combined with the namespace, the FQDN becomes backend.FCAJResbar.internal.
Description Backend Service Discovery Name Brief description of the service’s role.
Discoverable by API and DNS Allows discovery via both DNS queries and Cloud Map API.

4.7

Save the Full Service Discovery Name
With the service name backend and namespace FCAJResbar.internal, the Fully Qualified Domain Name (FQDN) is:
backend.FCAJResbar.internal

Please make a note of this domain name. In Step 6.2 (Frontend Task Definition), we will set the environment variable:
BACKEND_HOST = backend.FCAJResbar.internal
BACKEND_PORT = 3000

  1. In the DNS Configuration section:
    • Routing policy: Select WEIGHTED (or Multivalue answer, depending on your configuration).
    • Record type: Select A (Resolves the service name to IPv4 addresses of ECS tasks).
    • TTL: Enter 300 seconds.
    • Health check option: Select No health check.

4.8

Why select “No health check” in Cloud Map?
Amazon ECS manages its own task health checks (via container health checks and ALB target groups). When integrated with ECS, ECS automatically notifies Cloud Map when a task is healthy or stopped. Therefore, additional Cloud Map-level Route 53 health checks are unnecessary and would incur extra Route 53 health checking charges.

  1. Click Create service.
  2. Cloud Map will process the request. After a brief period, your service will display with a status of Success.

4.10

  1. Cloud Map also automatically creates Route 53 Private Hosted Zone fcajresbar.internal in Route 53 console, we can verify it by going to the Route 53 console and selecting Private Hosted Zones and we should see fcajresbar.internal there.

4.11

  1. We can also see there is one A record created for the service backend and it will point to the IP address of the ECS task. This record will be updated automatically when the ECS task is updated or scaled.

4.12


Verification and Key Takeaways

Let’s review what was configured and how it will be used in subsequent lab modules:

Component Configured Value Usage in Lab
Namespace FCAJResbar.internal Acts as the private DNS domain inside our VPC.
Service backend Registered under the namespace.
FQDN backend.FCAJResbar.internal Used in Step 6.2 by Frontend containers to reach the Backend API.
Integration Amazon ECS Service Discovery In Step 8.1, when creating the Backend ECS service, we will link it to this backend service so tasks automatically register their private IPs here.