Is there a way to set up priorities for target groups, not weights?

Viewed 156

There is an ability to forward requests to multiple weighted target groups. Is there a way to set up priorities for target groups, not weights? What I'm trying to achieve is: I wanna have a rule which would have 2 tgs, one with scaled down ecs services (to 0) and another one with lambdas. If I need a performance boost (to avoid lambda warmups) I wanna be able to scale up the ecs cluster and it should overtake the request handling. That would be very nicely possible if I could set up two target groups as I described. When the number of healthy targets in ecs will be 0, it won't be able to handle any requests and the infra would route all the requests to the lambda target group. When the number of healthy targets in ecs will be 1 and more, based on the priority, all the requests will go to it. Is that possible? If not, what is the alternative approach to achieve what I have described?

1 Answers

You are basically asking for a failover mechanism. You want to route requests to the primary Target Group. Then if it goes unhealthy, route to the next Target Group based on the priority score. However, this article specifically mentions failover between target groups is not supported by default.

The Application Load Balancer distributes traffic to the target groups based on weights. However, if all targets in a particular target group fail health checks, then the Application Load Balancer doesn't automatically route the requests to another target group or failover to another target group. In this case, if a target group has only unhealthy registered targets, then the load balancer nodes route requests across its unhealthy targets. A weighted target group should not be used as a failover mechanism when all the targets are unhealthy in a specific target group.

However, if your problem is just the Lambda cold start, you can always schedule a ping to your Lambda every 5 minutes. I would think this is much easier than having to duplicate the same endpoint in ECS, especially from ops and maintenance perspective.

Finally, may be obvious, but if you really want it, you can always implement a script to do so.

EDIT

There is another way using Route 53, since it has a failover mechanism. Create 2 ALBs, one backed by ECS and another by Lambda. Use the failover routing.

Related