ecs service multiple target group

2022. 10. 25. 09:12AWS/Amazon Elastic Container Service

728x90
SMALL

- 개요

ECS Service에 다중 LB 및 TG 를 사용이 요구 되는 경우는 종종 있다. Internal & External 을 사용하는 경우가 대표적이다. 그럴 경우 콘솔에서는 안되지만 CLI, SKD 등을 사용해서 생성이 가능하다. ECS Service에 TG를 여러 개 붙히려고 한다면 AWS Web Console에서는 불가능하여 CLI로 하는 방법을 정리했다.

 

 

 - 방법

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>
}

 

 

- 참고

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

 

728x90
LIST