Files
floci/docs/services/cloudmap.md
T
Abhigya 53de56f487 feat(cloudmap): honor service TTL in DNS A answers (#4448)
* feat(cloudmap): honor service TTL in DNS A answers

* fix(cloudmap): distinguish DNS no-data and reject case collisions

* fix(cloudmap): resolve SRV instance A hostnames

* refactor(cloudmap): simplify DNS answer states and resolver

Give DnsAnswer explicit records, noData and nxDomain factories, drop the
test-only buildAResponse overload, split Cloud Map name resolution into
service and instance-hostname lookups, and parse DnsConfig once on
CreateService.

* fix(cloudmap): lowercase DNS names independent of the default locale

* fix(route53): answer private zone DNS with the record set TTL

Port Route53DnsRecordSource to DnsAnswer after rebasing onto #4353. Answers
carry the record set TTL, a flattened CNAME chain uses the shortest TTL in
the chain, and an alias uses its target's. A name absent from the zone gets
NXDOMAIN; a name with records but no A gets NOERROR with no answers.

* fix(route53): answer empty non-terminals with no data and cap external CNAME TTL

A private zone name with records only beneath it exists in DNS, so it now
answers NOERROR with no A records instead of NXDOMAIN. A CNAME to a name
outside the private zones answers with at most 60 seconds, matching the
alias path, since the target's own TTL is not visible.

* fix(route53): stop wildcards matching at or beneath empty non-terminals

A name with records only beneath it exists, so under RFC 4592 a wildcard
from a farther ancestor must not answer for it or for names below it. The
closer-name check now counts any record sharing an ancestor with the query
name, including wildcard owners, so a closer wildcard also shadows a
parent wildcard.
2026-09-26 23:08:56 -04:00

7.5 KiB

AWS Cloud Map

Protocol: JSON 1.1 Header: X-Amz-Target: Route53AutoNaming_v20170314.<Action> Endpoint prefix: servicediscovery

Floci emulates the AWS Cloud Map (service discovery) control plane in-process: namespaces, services, and registered instances are stored as account-aware domain objects, and discovery queries resolve against that in-memory state.

Asynchronous operations (CreateHttpNamespace, CreatePublicDnsNamespace, CreatePrivateDnsNamespace, DeleteNamespace, RegisterInstance, DeregisterInstance) apply their effect synchronously and return an operation id. The operation reaches SUCCESS immediately by default, so a follow-up GetOperation call returns a completed operation without polling. No Route 53 hosted zones are created: public and private DNS namespaces are assigned a synthetic HostedZoneId so SDK and CLI clients can exercise the full Cloud Map control flow locally.

DNS resolution

A DNS namespace is answerable, not just storable. Floci's embedded DNS server resolves <service>.<namespace> to the AWS_INSTANCE_IPV4 of the instances registered under that service, one A record each, so a container that uses Floci as its resolver reaches its peers by name. Instances registered directly through RegisterInstance and instances an ECS service registers through its serviceRegistries resolve the same way.

Which instances answer follows Route 53: the healthy ones while any instance is healthy, and all of them when none is, so a service whose instances have all gone unhealthy still resolves rather than disappearing from DNS. At most eight records go back either way, as Route 53 answers a service discovery query. Names inside a DNS namespace stay local when no instance has a usable address: the resolver answers negatively instead of forwarding them to upstream DNS. An absent service name receives NXDOMAIN; a service with registered instances and only other record types receives NOERROR with no A answers. DNS service names are unique without regard to case, as in AWS Cloud Map.

A records carry the TTL of the service's A entry in DnsConfig.DnsRecords. A service configured for SRV also answers A queries at <InstanceId>.<service>.<namespace> when that instance has AWS_INSTANCE_IPV4. Those answers use the service's SRV TTL. The SRV service name itself has no A answer. Floci uses a 60-second fallback for older stored services without a usable A record TTL. New CreateService requests reject TTL values outside AWS's 0 to 2147483647 range. Names owned by Floci's embedded DNS server also use 60 seconds.

Three limits are worth knowing. HTTP namespaces do not resolve, matching AWS, where they are reachable only through DiscoverInstances. Only A records are served; SRV queries are not yet answered. The embedded DNS server only runs when Floci itself runs inside Docker, so name resolution is available to containers, not to processes on the host.

Supported Operations

Operation Notes
CreateHttpNamespace Creates an HTTP namespace; returns an operation id
CreatePublicDnsNamespace Creates a DNS_PUBLIC namespace with a synthetic HostedZoneId
CreatePrivateDnsNamespace Creates a DNS_PRIVATE namespace; requires Vpc, assigns a HostedZoneId
GetNamespace Returns a namespace by Id
ListNamespaces Lists namespaces in the current region
DeleteNamespace Deletes an empty namespace; fails with ResourceInUse if it still has services
CreateService Creates a service (optionally under a namespace), tracks revision and instance count
GetService Returns a service by Id
ListServices Lists services, optionally filtered by NamespaceId
DeleteService Deletes a service with no instances; fails with ResourceInUse otherwise
RegisterInstance Registers an instance under a service; requires InstanceId and Attributes, bumps service revision
DeregisterInstance Removes a registered instance and bumps service revision
GetInstance Returns a registered instance by ServiceId and InstanceId
ListInstances Lists instances registered under a service
GetInstancesHealthStatus Returns health status keyed by instance id, with optional Instances filter
DiscoverInstances Resolves instances by NamespaceName + ServiceName, with HealthStatus and QueryParameters filtering
DiscoverInstancesRevision Returns the current revision for a discovered service
GetOperation Returns an operation by Id
ListOperations Lists operations with optional STATUS, TYPE, NAMESPACE_ID, and SERVICE_ID filters
TagResource Adds tags to a namespace or service ARN
UntagResource Removes tag keys from a namespace or service ARN
ListTagsForResource Lists tags for a namespace or service ARN

DiscoverInstances supports the HEALTHY, UNHEALTHY, HEALTHY_OR_ELSE_ALL, and ALL health filters, and matches instances whose attributes contain every key/value pair supplied in QueryParameters.

Configuration

Variable Default Description
FLOCI_SERVICES_CLOUDMAP_ENABLED true Enable or disable the service
FLOCI_SERVICES_CLOUDMAP_OPERATION_COMPLETION_DELAY_SECONDS 0 Delay before an async operation transitions from PENDING to SUCCESS; 0 completes immediately

Examples

export AWS_ENDPOINT_URL=http://localhost:4566
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test

aws servicediscovery create-http-namespace --name floci-demo

aws servicediscovery list-namespaces

aws servicediscovery create-service \
  --name backend \
  --namespace-id ns-xxxxxxxxxxxxxxxxxxxx

aws servicediscovery register-instance \
  --service-id srv-xxxxxxxxxxxxxxxxxxxx \
  --instance-id i-0123456789 \
  --attributes AWS_INSTANCE_IPV4=10.0.0.10

aws servicediscovery discover-instances \
  --namespace-name floci-demo \
  --service-name backend
import boto3

client = boto3.client(
    "servicediscovery",
    endpoint_url="http://localhost:4566",
    region_name="us-east-1",
)

ns = client.create_http_namespace(Name="floci-demo")
client.get_operation(OperationId=ns["OperationId"])  # Status == "SUCCESS"

namespace_id = client.list_namespaces()["Namespaces"][0]["Id"]
service = client.create_service(Name="backend", NamespaceId=namespace_id)

client.register_instance(
    ServiceId=service["Service"]["Id"],
    InstanceId="i-0123456789",
    Attributes={"AWS_INSTANCE_IPV4": "10.0.0.10"},
)

found = client.discover_instances(NamespaceName="floci-demo", ServiceName="backend")
print(found["Instances"])

Out of Scope

  • Route 53 hosted zone / record set creation.
  • SRV, AAAA and CNAME record responses: AWS_INSTANCE_PORT is stored and returned, but only A records are served, including the companion A record for an SRV instance hostname.
  • Route 53 health checks backing HealthCheckConfig (custom health status is stored, not actively probed).
  • AWS_INIT_HEALTH_STATUS and AWS_EC2_INSTANCE_ID on RegisterInstance. Every instance registers HEALTHY, which is AWS's own initial status when AWS_INIT_HEALTH_STATUS is absent, so only a caller that explicitly asks for UNHEALTHY sees a difference.
  • Cross-region namespace and service discovery. A DNS query carries no region, so a name resolves through whichever namespace copy holds instances.