AWS Cloud Map allows you to set up some namespace for your VPC, and then assign names within that namespace to individual services. The names can either be A) privately discoverable only by API calls, B) discoverable via API calls or via DNS privately within the VPC, or C) discoverable via public DNS and by API calls. ECS can interact with Cloud Map to automatically register services. All this is referred to in AWS ECS as Service Discovery.
AWS ECS also has a relatively new thing called Service Connect. It leverages Cloud Map but also adds a sidecar "proxy" container to your ECS service, effectively creating an automatic service mesh.
I got Service Connect working with ECS using CloudFormation. In my CloudFormation AWS::ECS::Cluster
I configured ServiceConnectDefaults
to the Cloud Map namespace I want to use, such as example.internal
. Then I set enabled: true
for the AWS::ECS::Service
definitions under ServiceConnectConfiguration
, along with a few extra details such as providing a name for the service/port. Assuming I've named my service/port my-service
, I believe now that some other service using Service Connect in the same VPC could connect to my-service.example.internal
and the sidecar-proxy would figure out some instance of my-service
to connect to, without even using DNS! (I haven't tested that yet; I first wanted to get some clarification with the current question.)
But I would like private DNS access as well, if nothing else than to be able to go to Cloud9 and issue e.g. a curl my-service.example.internal/api/test
without needing to look up the IP address of one of the my-service
instances. I found out that I can define a AWS::ServiceDiscovery::PrivateDnsNamespace
and a AWS::ServiceDiscovery::Service
(using the same name my-service
) and even associate the latter with my ECS service using ServiceRegistries
. But then when I try to deploy my CloudFormation stack, I get an error:
Invalid request provided: CreateService error: Service already exists.
I'm guessing that internally to get Service Connect to work, ECS created its own AWS::ServiceDiscovery::Service
, at which point it saw that my CloudFormation stack had already created a AWS::ServiceDiscovery::Service
with the same name. But if I don't create AWS::ServiceDiscovery::Service
myself, the one that ECS creates won't provide a DNS entry for my-service
.
Am I to infer that AWS ECS can work with Service Connect (in which case there will be no service DNS entries, but the sidecar proxies will use API calls to look up registered services), or Service Discovery (in which I manually create Cloud Map DNS entries and ECS will automatically register them based upon the AWS::ServiceDiscovery::Service
I associate with the ECS service), but not both at the same time? Or did I configure something incorrectly?
I guess if I'm using Service Discovery and get DNS entries, I can simply indicate the (private in my case) DNS entries in the other services and they will find them via Cloud Map, providing me the same capabilities as Service Connect without the need for a sidecar proxy. But maybe Service Connect has some extra monitoring capabilities I'll be losing?
Can someone confirm is this a correct understanding, and elaborate on the practical differences and implications between using Service Connect or Service Discovery with ECS?