I have a docker image that I need to deploy, while maintaining a consistent DNS record. On top of that, I'd like to have a hard coded number of instances (for example, 2). I like the ease of ECS as well as ECS agent maintaining uptime, but a load balancer is overkill for a single instance. As of now I just create an ASG with min/max/desired as 1
so there isn't any conflicting issues.
There is a very heavy argument against numbering instances in an autoscaling group (here is one example), and that makes sense, though I think this is a pretty solid use case where it cannot be avoided.
I've successfully modified meltwater/terraform-aws-asg-dns-handler to give a single ECS instance within an ASG a hardcoded DNS record (say instance-1.example.com
), though its not very pretty. In order to get two instances working though (instance-1.example.com
and instance-2.example.com
), I think I have two options:
- create a hacky solution to read existing Route53 records in my Lambda function to "deterministically" decide which index to assign my instance in the ASG lifecycle hook (this could be a good start)
- create two ECS clusters, each with a single instance, and use two separate Lambda functions
Neither of these seem like very solid options to me so I'm wondering if there is a better way to deploy a single Docker container in an ECS-like manner that I can attach a DNS record to.
For context, the "two ECS cluster" approach would work fine, but I'm going to do this three or four times, so I would end up with 8 ECS clusters on top of a few others, which is inconvenient to say the least.