AlgoViz

AWS Cloud Map

easy 26 min

AWS Cloud Map is a managed registry: services and other cloud resources are registered under a name with attributes, and callers find them through an API or through DNS.

Video lesson · Chapter 1 of 5

One new order desk enters a private directory

0:00 / 4:27

AWS Cloud Map in 80 seconds

1:20Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

Containers and functions get new addresses each time they start. Something has to answer the question "where is orders now?". AWS Cloud Map is Amazon's managed answer: a registry where each running copy, or any other resource, is entered under a service name with a set of attributes. The general idea is explained in service discovery.

There are two ways to read it. An API call, DiscoverInstances, returns matching entries with all their attributes. And if the namespace was made for it, DNS answers with addresses, because Cloud Map writes the records into Amazon Route 53 for you. Cloud Map is a list. It does not carry traffic, balance load or run a proxy.

Why it exists

Without a registry, teams keep addresses in settings, or put a load balancer before every service. The first is wrong after each deployment. The second costs an extra hop and an extra bill for each of them. Cloud Map keeps the list current with no servers to run.

It can also name things that are not programs. A queue, a table or a web address can be registered under a stable name, with attributes such as the stage, so that the same code finds the right one in test and in production.

A short history

  1. 2017, December

    Amazon Route 53 Auto Naming is released on 5 December: names for IP addresses only, through DNS.

  2. 2018, March

    Amazon ECS announces service discovery on 22 March. Tasks are entered and removed automatically.

  3. 2018, November

    AWS Cloud Map is announced on 28 November. It adds an API, attributes, and any resource with a URL or ARN. Auto Naming entries move into it.

  4. 2022, November

    Amazon ECS Service Connect is announced. It uses Cloud Map namespaces and adds a managed proxy to each task.

  5. 2024 and 2025

    Service-level attributes arrive in December 2024, and sharing a namespace with other accounts in August 2025.

  6. 2026, September

    AWS App Mesh, a mesh that could use Cloud Map for discovery, reaches its end of support on 30 September. AWS points ECS users to Service Connect.

Words to know

Namespace
The outer name, such as shop.local. It also decides how entries can be found: API only, DNS in private networks, or public DNS.
Service
A named group inside a namespace, with its DNS and health settings. It is the template for its entries.
Instance
One entry: a container, a machine, a queue, a table. It has an ID and attributes.
Attribute
A key and a value on an entry. Some keys are reserved, such as AWS_INSTANCE_IPV4; the rest are yours.
Custom health check
You, or ECS, tell Cloud Map the state. Cloud Map does not test the entry itself.
Revision
A number that grows when entries are added or removed, so that a client can ask cheaply whether anything changed.

How it works

Step through the idea, or press Play.

Step 1 of 3

Register. ECS or your program adds an entry with attributes

Understand it

Start here

Coat pegs with picture labels

Picture a nursery. The children cannot read, so each has a picture: a duck, a star, a boat. Every room has a row of pegs by the door. A label on the peg says who is inside.

Who is in the red room?
Red roomBlue room

The pegs tell you where to go. You still walk there yourself.

The model

Namespace, service, instance

Three levels

The DNS name is the service and the namespace together: orders.shop.local.

Three kinds of namespace

KindFound withEntriesWhat is created
HTTPAPI onlyAnything: IPs, URLs, ARNsOnly the namespace
Private DNSAPI, and DNS inside chosen VPCsDNS needs IP addressesA private hosted zone in Route 53
Public DNSAPI, and DNS on the internetDNS needs IP addressesA public hosted zone in Route 53
A namespace belongs to one Region. For two Regions, make two. A service in a DNS namespace may also be set to API only.

What an entry can hold

  • Address

    AWS_INSTANCE_IPV4, AWS_INSTANCE_IPV6 and AWS_INSTANCE_PORT become A, AAAA and SRV records.

  • Load balancer

    AWS_ALIAS_DNS_NAME makes an alias record. Set through the API or CLI, with weighted routing.

  • Your own facts

    Up to 30 custom attributes: version, zone, weight, a queue URL. All together at most 5,000 characters.

  • First state

    AWS_INIT_HEALTH_STATUS sets the state at the start. Without it, a custom check begins as HEALTHY.

Architecture

Where it sits

A registry beside the traffic

Inside our AWS account, the ECS service scheduler registers orders tasks in Cloud Map, and Cloud Map writes records to a Route 53 private zone. The web task asks Cloud Map by API or Route 53 by DNS, and then calls an orders task directly.
ECS writes the entries. The web task reads them, by API or by DNS, and calls an orders task directly.

Cloud Map does

  • Keeps entries and attributes, with nothing to run
  • Answers API calls, filtered by attribute and health
  • Writes and removes Route 53 records
  • Takes health reports
  • Uses IAM for who may read and write
  • Shares a namespace with other accounts

Cloud Map does not

  • Carry or encrypt traffic
  • Balance: the caller chooses among the answers
  • Retry, time out or break circuits
  • Test private addresses for you
  • Span Regions by itself
  • Offer locks or leader election

Register

Three ways in

Who registersHowWatch out for
Amazon ECSService discovery or Service Connect on the serviceTasks with container health checks wait until they pass
KubernetesExternalDNS with the AWS Cloud Map providerExtra controller; inside a cluster its own Services are enough
Your program or pipelineRegisterInstance and DeregisterInstanceA crash leaves the entry behind

Registering is asynchronous: the call returns an operation ID, and GetOperation says when it is finished. Use the same instance ID to replace an entry. A program that registers itself must also remove itself, and something must clean up after a crash, which is why letting the platform register is safer.

An ECS task joins and leaves

AWS says that ECS tasks become discoverable within five seconds. Records that callers cached live on until their time ends.

Discover

API or DNS?

DiscoverInstances (API)DNS
ReturnsAll attributes: IP, port, URL, ARN, your ownIP addresses; ports with SRV
FilterHealth and attributesNone
FreshnessChanges within about 5 secondsPlus the TTL, plus whatever the program caches
How many100 by default, up to 1,000Up to 8 (multivalue) or 1 (weighted)
Caller needsThe AWS SDK and IAM rightsOnly a name
Limit1,000 per second steady, burst 2,000, per account and RegionThe resolver's: 1,024 packets per second per network interface
BillingPer callRoute 53 query prices

Which one?

Routing policy decides the DNS answer. With *multivalue*, up to eight healthy addresses come back. With *weighted*, one is chosen at random, and all have the same weight, so you cannot send less traffic to one. Alias records to a load balancer need weighted. Eight addresses out of fifty are fine when many callers look up often, since the answers differ.

Will the API limit hold?

q=tasks×namesseconds between calls2000×1015≈1333>10002000×1030≈667q = \frac{\text{tasks} \times \text{names}}{\text{seconds between calls}} \qquad \frac{2000 \times 10}{15} \approx 1333 > 1000 \qquad \frac{2000 \times 10}{30} \approx 667
Assumptions: 2,000 tasks, each watching 10 names. Every 15 s is too often for the default limit; every 30 s fits. Asking DiscoverInstancesRevision first (3,000 per second) and reading the list only after a change fits even at 15 s.

Freshness

How long can a dead address live?

Worst case with DNS and a custom check

t=tdetect+30+tchange+TTL20+30+5+60=115 secondst = t_{detect} + 30 + t_{change} + TTL \qquad 20 + 30 + 5 + 60 = 115\ \text{seconds}
Assumptions: your checker needs 20 s to notice, changes spread in 5 s, TTL is 60 s. The 30 s is Cloud Map's own wait before it accepts a custom UNHEALTHY. Choosing a TTL of 10 s saves 50 s; a caller with a 1 s timeout and a second try hides the rest.

A cached answer outlives its entry

So a service must keep answering for at least one TTL after it was removed, and callers need timeouts and retries.

Health

Two kinds of check, one trap

CheckWorks forHow
Route 53 health checkPublic DNS services, and API namespaces with reachable addressesCheckers in several Regions, each every 30 s; a threshold of 1 to 10 results. Separate charge
Custom health checkAnything, also private addressesYour checker, or ECS, calls UpdateInstanceCustomHealthStatus
NoneAnythingEvery entry counts as healthy
Private DNS services cannot use Route 53 health checks, since the checkers sit outside your network.

After a first report of UNHEALTHY, Cloud Map waits about 30 seconds. If no HEALTHY report arrives in that time, the entry is out. Sending the same report again does not shorten the wait.

HealthStatus in DiscoverInstances

ValueReturns
HEALTHYOnly healthy entries: may be an empty list
HEALTHY_OR_ELSE_ALLHealthy ones; if there are none, all of them (failing open)
UNHEALTHYOnly unhealthy entries, for a dashboard
ALLEverything
DNS fails open on its own: if no entry is healthy, Route 53 answers as if all were.

On ECS

Service discovery or Service Connect

ECS service discoveryECS Service Connect
What it isEntries and DNS names for tasksThe same names plus a managed proxy in each task
BalancingWhatever the caller does with the DNS answerRound robin in the proxy, with outlier detection
Who can resolveAnything in the VPCTasks in the same namespace that use Service Connect
MetricsNone of its ownTraffic metrics in ECS and CloudWatch
Cloud Map costNo charge for the entries; lookups are chargedNo charge for Cloud Map
Service Connect adds work inside the task: give it processor and memory. It is the usual first choice between ECS services.
Shell
# A private name for tasks, answered inside one VPCaws servicediscovery create-private-dns-namespace \  --name shop.local --vpc vpc-0exampleaws servicediscovery create-service \  --name orders --namespace-id ns-example \  --dns-config 'RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=10}]' \  --health-check-custom-config FailureThreshold=1# ECS then keeps the entries:aws ecs create-service --cluster shop --service-name orders \  --task-definition orders:7 --desired-count 2 --launch-type FARGATE \  --network-configuration 'awsvpcConfiguration={subnets=[subnet-0example]}' \  --service-registries registryArn=arn:aws:servicediscovery:eu-west-1:111122223333:service/srv-example
The IDs are examples. The TTL is the number to think about: short enough for your recovery goal, long enough for your lookup rate.

Uses

More than addresses

  1. 1

    A queue by name

    Register the queue URL as an attribute under events. Code asks for stage = test or stage = prod, and the URL is never written into the build.

  2. 2

    Two versions side by side

    Entries carry version = 1 or 2. A caller passes version = 2 in QueryParameters for a canary. OptionalParameters are a wish: they are ignored if nothing matches.

  3. 3

    Stay in the zone

    ECS adds AVAILABILITY_ZONE to each entry. Ask for your own zone as an optional parameter to save cross-zone traffic.

  4. 4

    Settings for a service

    Service attributes, since December 2024, hold values such as a timeout or a weight once, and need not be repeated on every entry.

Operate

Limits, safety and cost

Default quotas per Region

WhatDefaultCan be raised
Namespaces50Yes
Instances per namespace2,000Yes
Instances per service1,000No
Custom attributes per instance30No
DiscoverInstances per account1,000 per second, burst 2,000Yes
DiscoverInstancesRevision per account3,000 per secondYes
Raising instances in a DNS namespace also needs a higher Route 53 limit on records per zone, at extra cost.

When the limit is passed, calls fail with RequestLimitExceeded. Keep the last good list, wait longer after each failure, and add some randomness; see retries. The limit is a token bucket, described in rate limiter algorithms.

Run it well

  1. 1

    Rights

    Let callers discover, and let only the platform register. An attacker who can register can send your traffic elsewhere.

  2. 2

    Private path

    Use an AWS PrivateLink endpoint so that API calls do not need the internet.

  3. 3

    Clean up

    Alert on entries that fail for an hour. Deregister before stopping, then wait one TTL.

  4. 4

    Accounts

    Share a namespace through AWS Resource Access Manager. For private DNS, the other account's network must also be joined to the hosted zone, and it needs a network path.

  5. 5

    Cost

    You pay per registered resource and per discovery call, plus Route 53 for zones, queries and checks. Polling is usually the largest part, so poll the revision or use DNS.

Decide

When to choose it, and when not

Choose Cloud Map

  • Services on ECS that call each other
  • Several AWS accounts sharing names
  • You need attributes: version, zone, stage
  • Functions and machines must find the same resources
  • Nobody wants to run a registry

Choose something else

  • Public traffic: use a load balancer
  • All inside one Kubernetes cluster: use its Services
  • Other clouds or your own data centre as equals
  • You need encryption and permission by service: use a mesh
  • Failover within a second or two by DNS alone

Neighbours

OptionSameDifferentChoose it when
Load balancerOne stable nameCarries traffic, checks targets, one extra hopPublic entry, or callers that cannot balance
ConsulRegistry with DNS and APIYou run it; any platform, locks, meshMixed clouds and machines
Kubernetes ServicesNames for copiesBuilt into one clusterEverything is in it
Amazon VPC LatticeService names across accountsCarries the traffic, with access policiesYou want routing and permission with no proxy to run
Parameter StoreNames for valuesNo health, no DNSThe value changes rarely

Summary

The whole topic in one minute.

Cloud Map stores entries in namespaces and services. Callers read them with DiscoverInstances, which is fresh and can filter by attribute, or with DNS, which needs no code and may be cached. Health comes from Route 53 checks for public names, or from your own reports.

Use it for services on AWS, above all on ECS, when direct calls between copies are wanted. Add timeouts, retries and balancing in the caller or in a proxy, because a list can always be a little old.

  • Namespace, service, instance: a managed list with attributes.
  • The API is fresh and can filter; DNS needs no code and may be cached.
  • Private entries need custom health reports, and UNHEALTHY takes about 30 seconds.
  • Poll the revision number to stay under 1,000 calls per second.
  • A dead address can live for detection plus 30 seconds plus the TTL, so callers retry.
  • On ECS, Service Connect adds the proxy that balances.

Sources