I'm searching for a way to add a domain name to an ECS service (containers) without a load balancer.
The particular type of service I want to do this for is itself a load balancer with capabilities outside of AWS's offering. We need this to be redundant across availability zones with similar setups in multiple isolated VPCs. I'm really loathed to spend $2000 per year to put in enough loadbalancers to fulfil this simple requirement.
To be clear I'm looking for a solution which resolves an FQDN to an external IP address attached to the container so A or AAAA name (possibly CNAME if its weighted and points to an A or AAAA). It doesn't matter to me which network mode this works for. The container can be placed in any of host
, bridge
, awsvpc
if the solution works!
So far I've found this frustratingly limited:
- Service Discovery will only add SRV records for
host
andbridge
type network containers - Service Discovery will create A and AAAA records for
awsvpc
network type containers, butawsvpc
tasks can't be placed on ECS EC2 instances and still have a public IP address. - Running the same tasks in fargate would cost as much or more than the load balancers.
- Route53 has no good mechanism for adding A and AAAA name records to EC2 instances in an autoscaling group so even if I put an instance of this task on every node I still won't be able to reference it by domain name.
How to add a domain name to an ECS container without a load balancer?
I am not clear about the question. Service Discovery does support a domain name (namespace). It's actually mandatory as far as I can tell. In other words if you want to use SD for an ECS service called
myservice
you have to refer to it asmyservice.<domain>
where<domain>
is an arbitrary namespace you have to define (such as .local or .my.domain). Here is an example of a stack that uses SD.Note that all this is internal to the cluster and how internal service discovery works (e.g. how an ECS service discovers another ECS service).
[Edit] IF you want to expose your ECS services but DO NOT want to use a load balancer another option would be to use API GW as described in this blog post. In general you do not want to register random public IP addresses of Fargate tasks in R53 because they are ephemeral and you'd need to build complex mechanism to keep them aligned when Fargate tasks come and go. Have you also considered App Runner?