1
votes

I have an AWS ECS Service running in the Fargate mode. My setup has two tasks running an httpd image (Apache2) listening on port 80. I have an application load balancer that redirects port 80 to a target group. That target group is configured with two IPs (each task exposes on private IP, hence two IPs in the target group.

I have a question around auto scaling on ECS Services: how does the auto scaling will work in terms of assigning IPs to the target group? That is an essential part of of the scaling-out mechanism since if the new task's private IP is not assigned to the target group then that new container/task won't get any traffic, which counters the entire purpose of auto scaling.

1
ECS manages this, so you don't have to worry about registering new tasks with TG. Have you observed that it does not work for you?Marcin

1 Answers

2
votes

Correct. That's why when you configure ECS you tell ECS what the target group for the service is. Behind the scenes ECS will add/remove the tasks IPs to/from the LB target group. It's part of the built-in integration between ECS and other AWS services (LB in this case).

For example, if you were to do this from the CLI, this is the command you'd be running when creating the service:

aws ecs create-service --service-name scale-out-app --cluster app-cluster --load-balancers "targetGroupArn=$TARGET_GROUP_ARN,containerName=scale-out-app,containerPort=80" --task-definition scale-out-app --desired-count 4 --launch-type FARGATE --platform-version 1.4.0 --network-configuration "awsvpcConfiguration={subnets=[$PRIVATE_SUBNET1, $PRIVATE_SUBNET2],securityGroups=[$SCALE_OUT_APP_SG_ID],assignPublicIp=DISABLED}" --region $AWS_REGION

In this specific case targetGroupArn=$TARGET_GROUP_ARN is what wires the service to the target group and ECS knows what to do.

Makes sense?