Service Discovery with AWS Cloud Map - Dynamic Name Resolution for Microservices
Dynamically discover microservice endpoints using DNS-based and API-based approaches. Learn how to automate service registration and deregistration through integration with ECS and EKS.
Overview of Cloud Map
Cloud Map is a service that provides service discovery for application resources. In a microservices architecture, when Service A needs to call Service B, instead of hardcoding Service B's endpoint, it queries Cloud Map for dynamic resolution. Cloud Map offers two discovery methods (DNS-based and API-based) and integrates with ECS and EKS to automate service registration and deregistration.
DNS and API Discovery
A DNS namespace registers services as DNS records, resolving them via DNS names like service-b.my-namespace.local. Existing applications can discover services through DNS queries without any code changes. An HTTP namespace retrieves service instances via the DiscoverInstances API, with filtering by custom attributes (version=v2, environment=prod). ECS service discovery automatically registers instances in Cloud Map when tasks launch and deregisters them when tasks stop. Route 53 health checks detect unhealthy instances and exclude them from discovery results.
Integration with ECS and EKS
When you enable Cloud Map on an ECS service, service instances are automatically registered and deregistered as tasks start and stop. With DNS-based discovery, SRV or A records are created in Route 53, and clients resolve services by DNS name. With API-based discovery, the DiscoverInstances API returns a list of health-checked instances, and clients implement load balancing on their side. In EKS, the AWS Cloud Map MCS Controller automatically syncs Kubernetes Services to Cloud Map. For health checks, you can choose between Route 53 health checks or custom health checks (where the application calls the UpdateInstanceCustomHealthStatus API). For a comprehensive study of service discovery patterns, refer to technical books on Amazon.
Cloud Map Pricing and Operations
Cloud Map pricing is based on the number of registered resources and API calls. DNS queries are charged at standard Route 53 rates, and the DiscoverInstances API costs $1 per million requests. In auto-scaling environments where instance registration and deregistration occur frequently, API call volume increases, so implementing client-side caching helps control costs. For namespace design, separate namespaces by environment (dev/staging/prod) and keep service names consistent across environments to eliminate environment-specific dependencies in application code. Monitor DiscoverInstances call counts and latency with CloudWatch metrics to detect abnormal increases.
Summary
The easiest entry point for Cloud Map is through ECS service discovery integration. Simply enabling Cloud Map on an ECS service automates service registration in sync with task starts and stops. Choose a DNS namespace if your existing applications resolve names via DNS, or an HTTP namespace if you need filtering by custom attributes. For namespace design, separate by environment (dev/staging/prod) and keep service names consistent across environments.