AWS Cloud Map
A phone book for your own backend. Every component registers itself — "I'm payments, I'm at 10.0.3.17:8080, I'm version v2, I'm healthy" — and callers look it up by name instead of hardcoding an address. When instances come and go, nobody redeploys.
Một cuốn danh bạ cho backend của chính bạn. Mỗi thành phần tự đăng ký — "tôi là payments, ở 10.0.3.17:8080, phiên bản v2, đang khoẻ" — và bên gọi tra theo tên thay vì nhét cứng địa chỉ. Instance lên xuống liên tục mà không ai phải deploy lại.
Reach for it / not the right toolKhi nào dùng / khi nào không
Reach for Cloud MapChọn Cloud Map
- Microservices that need to find each other, on infrastructure that changes constantly — containers, Spot instances, serverless.Microservice cần tìm lẫn nhau, trên hạ tầng thay đổi liên tục — container, Spot instance, serverless.
- You need to pick an endpoint by more than a name — version, AZ, tenant, capability. That's what custom attributes are for.Cần chọn endpoint theo nhiều hơn cái tên — version, AZ, tenant, năng lực. Đó là việc của custom attribute.
- A registry of things a load balancer can't front — a DynamoDB table name, a queue URL, an S3 bucket per tenant.Một registry cho những thứ load balancer không đứng trước được — tên bảng DynamoDB, URL queue, bucket S3 theo tenant.
- ECS tasks on awsvpc networking that need direct task-to-task addressing without an internal ALB.Task ECS dùng mạng awsvpc cần gọi thẳng task-to-task mà không cần ALB nội bộ.
Not the right toolKhông phải chỗ dùng
- There's a stable front door already — an ALB or API Gateway DNS name doesn't change, so callers can just use it.Đã có cửa trước ổn định — tên DNS của ALB hay API Gateway không đổi, bên gọi cứ dùng thẳng.
- Routing public internet traffic, latency/geo/failover policies → CloudFront and Route 53.Định tuyến traffic internet công cộng, chính sách latency/geo/failover → CloudFront và Route 53.
- Retries, timeouts, circuit breaking, mTLS between services — Cloud Map only says where things are, never how to talk to them.Retry, timeout, circuit breaking, mTLS giữa các service — Cloud Map chỉ nói ở đâu, không bao giờ nói giao tiếp thế nào.
- Pure Kubernetes workloads — CoreDNS already does in-cluster discovery. Cloud Map earns its place when you must reach outside the cluster.Workload Kubernetes thuần — CoreDNS đã lo discovery trong cluster. Cloud Map chỉ đáng giá khi cần với ra ngoài cluster.
The problem — hardcoded endpointsVấn đề — endpoint nhét cứng
Service discovery is the problem of one component finding another's current address. Bake the address into config and every scale event, redeploy or failover turns into a code change. Cloud Map replaces "I know where you are" with "I'll ask". Service discovery là bài toán một thành phần tìm ra địa chỉ hiện tại của thành phần khác. Nhét địa chỉ vào config thì mỗi lần scale, deploy lại hay failover đều thành một lần sửa code. Cloud Map thay "tôi biết bạn ở đâu" bằng "để tôi hỏi".
The registry is the only thing that knows the current address, and it learns it from the instance itself. Everything else asks.
Registry là thứ duy nhất biết địa chỉ hiện tại, và nó học điều đó từ chính instance. Mọi bên khác đều đi hỏi.
Namespace → Service → InstanceNamespace → Service → Instance
Three levels, and the names are literal. A namespace is the directory, a service is one logical thing in it, and an instance is one running copy with its attributes. Ba tầng, và tên gọi đúng nghĩa đen. Namespace là thư mục, service là một thứ logic trong đó, và instance là một bản đang chạy kèm thuộc tính của nó.
Both paths read the same registry. DNS is universal but lossy — it can only hand back an address. The API is the reason Cloud Map exists rather than just a private hosted zone.
Cả hai đường đều đọc cùng một registry. DNS phổ dụng nhưng mất thông tin — nó chỉ trả về được địa chỉ. API mới là lý do Cloud Map tồn tại thay vì chỉ một private hosted zone.
The three namespace typesBa loại namespace
| TypeLoại | What it creates · how you query itTạo ra gì · tra thế nào |
|---|---|
| HTTP | No DNS at all — API discovery only. Cheapest and simplest; pick it when every caller uses the AWS SDK anyway.Không có DNS — chỉ discovery qua API. Rẻ và đơn giản nhất; chọn khi mọi bên gọi vốn đã dùng AWS SDK. |
| Private DNSPrivate DNS | A Route 53 private hosted zone attached to your VPC. Resolvable only inside it. DNS and API. This is the common choice.Một private hosted zone Route 53 gắn vào VPC. Chỉ resolve được bên trong. Cả DNS lẫn API. Đây là lựa chọn phổ biến. |
| Public DNSPublic DNS | A public hosted zone — you must own the domain. Resolvable from the internet. DNS and API, and the only type that can use Route 53 health checks.Một public hosted zone — bạn phải sở hữu domain. Resolve được từ internet. Cả DNS lẫn API, và là loại duy nhất dùng được Route 53 health check. |
The thing DNS can't doThứ DNS không làm được
A DNS answer is a list of addresses and nothing else. DiscoverInstances returns the attributes you registered and lets you filter on them server-side — so "give me only healthy v2 instances in this AZ" is one call, not a lookup plus your own filtering logic.
Một câu trả lời DNS là danh sách địa chỉ, không hơn. DiscoverInstances trả về các thuộc tính bạn đã đăng ký và cho lọc ngay phía server — nên "chỉ lấy instance v2 khoẻ mạnh trong AZ này" là một lời gọi, không phải tra rồi tự lọc.
# register — AWS_INSTANCE_* are reserved; everything else is yours
aws servicediscovery register-instance \
--service-id srv-a1b2c3 \
--instance-id backend-7f3a \
--attributes AWS_INSTANCE_IPV4=10.0.3.17,AWS_INSTANCE_PORT=8080,version=v2,az=a
# discover — filter server-side on your own attributes
aws servicediscovery discover-instances \
--namespace-name myapp.internal \
--service-name backend \
--query-parameters version=v2 \
--health-status HEALTHY
version=v2, have 5% of callers ask for it, and shift the ratio in the caller — no listener rules, no target groups. It's also how you do cell / tenant routing: tenant=acme returns exactly the instances that hold that tenant's data.
Lọc theo thuộc tính chính là canary routing mà không cần load balancer. Đăng ký bản build mới với version=v2, cho 5% bên gọi hỏi nó, rồi chỉnh tỉ lệ ngay ở phía gọi — không listener rule, không target group. Đây cũng là cách làm routing theo cell / tenant: tenant=acme trả về đúng các instance giữ dữ liệu của tenant đó.
Health checkingKiểm tra sức khoẻ
Health is stored in the registry, so filtering happens before you ever get an address — an unhealthy instance is simply absent from the answer. Tình trạng sức khoẻ lưu trong registry, nên việc lọc xảy ra trước khi bạn nhận địa chỉ — instance không khoẻ đơn giản là vắng mặt trong câu trả lời.
UpdateInstanceCustomHealthStatus. The right answer for private addresses — which is most of them.Bạn tự báo trạng thái bằng UpdateInstanceCustomHealthStatus. Đáp án đúng cho địa chỉ private — tức là hầu hết trường hợp.
Where you'll actually meet it — ECSNơi bạn thực sự gặp nó — ECS
Most people never call the Cloud Map API directly. They tick a box on an ECS service and Cloud Map appears underneath. Phần lớn người dùng chẳng bao giờ gọi API Cloud Map trực tiếp. Họ tick một ô trong ECS service và Cloud Map hiện ra bên dưới.
-
ECS Service Discovery — enable it on a service and ECS registers each task as an instance when it starts and deregisters it when it stops. With
awsvpcnetworking every task has its own IP, so this gives you real task-to-task addressing with no internal load balancer. ECS Service Discovery — bật trên một service và ECS đăng ký mỗi task thành một instance khi khởi động, huỷ đăng ký khi dừng. Với mạngawsvpcmỗi task có IP riêng, nên bạn có địa chỉ task-to-task thật mà không cần load balancer nội bộ. - ECS Service Connect is the newer option and also uses Cloud Map namespaces — it adds a proxy sidecar, so you get retries, connection pooling and per-service traffic metrics that plain service discovery can't give you. ECS Service Connect là lựa chọn mới hơn và cũng dùng namespace Cloud Map — nó thêm một proxy sidecar, nên bạn có retry, connection pooling và metric traffic theo từng service mà service discovery thuần không cho.
- Rough rule: Service Discovery = "just tell me the addresses" · Service Connect = "and manage the connection too" · internal ALB = "and I want listener rules, TLS termination and path routing". Quy tắc thô: Service Discovery = "chỉ cho tôi địa chỉ" · Service Connect = "và quản luôn kết nối" · ALB nội bộ = "và tôi cần listener rule, TLS termination, path routing".
- On EKS, in-cluster discovery is CoreDNS's job. Cloud Map is the bridge when things outside the cluster — a Lambda, an EC2 fleet, another account — need to find pods. Trên EKS, discovery trong cluster là việc của CoreDNS. Cloud Map là cầu nối khi những thứ ngoài cluster — một Lambda, một fleet EC2, một account khác — cần tìm pod.
Cloud Map vs the things it's confused withCloud Map và những thứ hay bị nhầm
| What it answersNó trả lời gì | Tell them apart byPhân biệt bằng | |
|---|---|---|
| Cloud Map | "where is backend v2 right now, and is it healthy?""backend v2 giờ ở đâu, và có khoẻ không?" | a registry with an API and custom attributes; things register themselvesmột registry có API và custom attribute; các thành phần tự đăng ký |
| Route 53 | "what IP is this name?""tên này ứng với IP nào?" | DNS. Records are managed by you, cached by TTL, and carry no metadata. Cloud Map uses it underneath for DNS namespaces.DNS. Record do bạn quản, bị cache theo TTL, và không mang metadata. Cloud Map dùng nó bên dưới cho DNS namespace. |
| Internal ALBALB nội bộ | "send this request to something that works""gửi request này tới cái gì đó còn chạy được" | It sits in the traffic path and picks for you. Cloud Map never sees your traffic — the client connects directly.Nó nằm trên đường traffic và chọn hộ bạn. Cloud Map không bao giờ thấy traffic — client kết nối thẳng. |
| Service ConnectService Connect | "where is it, and handle the connection""nó ở đâu, và lo luôn kết nối" | a proxy sidecar on top of a Cloud Map namespace — retries and metrics includedmột proxy sidecar đặt trên namespace Cloud Map — kèm retry và metric |
Exam reflexesPhản xạ khi thi
| The question says…Đề nói… | AnswerTrả lời |
|---|---|
| "Microservices must find each other as instances constantly come and go""Microservice phải tìm được nhau khi instance liên tục lên xuống" | Cloud Map (via ECS Service Discovery if it's ECS)Cloud Map (qua ECS Service Discovery nếu là ECS) |
| "Select endpoints by version / attribute, not just by name""Chọn endpoint theo version / thuộc tính, không chỉ theo tên" | DiscoverInstances with custom attributes — DNS cannot do thisDiscoverInstances với custom attribute — DNS không làm được |
| "Register non-IP resources — a table, a queue — in one directory""Đăng ký tài nguyên không phải IP — bảng, queue — trong một danh mục" | Cloud Map with an HTTP namespaceCloud Map với HTTP namespace |
| "Callers are legacy and can only do a DNS lookup""Bên gọi là hệ thống cũ, chỉ biết tra DNS" | Private DNS namespace (not HTTP)Private DNS namespace (không phải HTTP) |
| "Stop sending traffic to unhealthy endpoints, in a private VPC""Ngừng gửi traffic tới endpoint không khoẻ, trong VPC private" | Custom health checks — Route 53 checks need public endpointsCustom health check — Route 53 check cần endpoint public |
| "There's already an ALB in front and its DNS name never changes""Đã có ALB đứng trước và tên DNS của nó không đổi" | You don't need Cloud Map — that's a distractorKhông cần Cloud Map — đó là đáp án gây nhiễu |