ecs service with multiple target group

Photo by Teng Yuhong on Unsplash

ecs service with multiple target group

AWS/Amazon Elastic Container Service

  • outline

Using ECS service, multiple target group can be used ocationally. Using both internal and external is common case for this. You can use multiple target group for a ECS service by CLI or SDK not Web Console.

  • how-to
aws ecs update-service --cluster <ecs-cluster> --service <service> --cli-input-json file://service.json
# service.json
{
  "cluster": "<ecs-cluster>",
  "service": "<ecs-service>",
  "desiredCount": <number>,
  "taskDefinition": "<taskdefinition>",
  "loadBalancers": [
    {
     "targetGroupArn": "<tg-arn-1>",
     "containerName": "<container>",
     "containerPort": <port>
    },
    {
     "targetGroupArn": "<tg-arn-2>",
     "containerName": "<container>",
     "containerPort": <port>
    }
  ],
  "deploymentConfiguration": {
    "maximumPercent": <percent>,
    "minimumHealthyPercent": <percent>
  },
  "networkConfiguration": {
    "awsvpcConfiguration": {
    "subnets": [
      "<subnet-yyyy>",
      "<subnet-xxxx>"
      ],
      "securityGroups": [
        "<sg-12343245235>"
      ],
      "assignPublicIp": "ENABLED"
    }
  },
  "forceNewDeployment": false,
  "healthCheckGracePeriodSeconds": <seconds>
}
  • reference

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. You must use UpdateService to modify the load balancer configuration of an existing service.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html
aws.amazon.com/ko/about-aws/whats-new/2019/..