0
votes

I'm attempting load balance a single application that's deployed with both fargate and ec2 ecs services. The reason being that I want to scale up with fargate briefly if necessary to cope with unexpected high loads. I can't seem to figure out how to configure the target groups/elastic load balancer.

For each service, I've created a corresponding target group with target_type set to "ip" and "instance" respectively for the fargate and ec2 service.

I'm not sure how to have the load balancer forward traffic to both of these target groups equally.

1

1 Answers

0
votes

https://docs.aws.amazon.com/AmazonECS/latest/userguide/register-multiple-targetgroups.html

Currently, if you want to create a service specifying multiple target groups, you must create the service using the Amazon ECS API, SDK, AWS CLI, or an AWS CloudFormation template. After the service is created, you can view the service and the target groups registered to it with the AWS Management Console.

Multiple target groups can be specified in a service definition using the following format.

"loadBalancers":[
   {  
      "targetGroupArn":"arn:aws:elasticloadbalancing:region:123456789012:targetgroup/target_group_name_1/1234567890123456",
      "containerName":"container_name",
      "containerPort":container_port
   },
   {  
      "targetGroupArn":"arn:aws:elasticloadbalancing:region:123456789012:targetgroup/target_group_name_2/6543210987654321",
      "containerName":"container_name",
      "containerPort":container_port
   }
]

As an alternative, I wonder if this would work

  • setup an ELB in front of just Fargate as normal
  • put the IP address of the Fargate ELB plus the IP addresses of your EC2 instances into a single target group with target_type set to ip