0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Fargateのコンテナに複数のターゲットグループをアタッチする方法

Last updated at Posted at 2025-03-21

はじめに

ALBとコンテナを使用した構成で、ALBからコンテナに接続する時、デフォルトは HTTP/80 に流すが、/health_check のパスの場合のみ HTTP/8080 に通信を流すような要件がでました。

上記のような設定を実現するには、マネジメントコンソール上では一つのターゲットグループにしかアタッチできない為、AWS CLIから設定する必要があるので備忘録として残しておきます。

構成図

Untitled_1__Qiita記事画像_-_Cacoo.png

設定コマンド

--load-balancers のオプションを使用する事で、複数のターゲットグループをアタッチできます。

  • 下記のコマンド実行の前提条件
    • VPC・ALB・ECSのサービス作成以外が完了している状態
    • 記載しているコマンドを使用する場合は、実際のARN等に置き換えて実行してください
aws ecs create-service \
 --cluster arn:aws:ecs:XXXXX:XXXXX:cluster/sample-cluster \
 --service-name sample-service \
 --task-definition sample-task:X \
 --load-balancers targetGroupArn=arn:aws:elasticloadbalancing:XXXXX:XXXXX:targetgroup/sample-container-tg/XXXXXX,containerName=sample-containe-01,containerPort=80 targetGroupArn=arn:aws:elasticloadbalancing:XXXXX:XXXXX:targetgroup/sample-container-health-check-tg/XXXXX,containerName=sample-containe-01,containerPort=8080 \
 --desired-count 1 \
 --launch-type FARGATE \
 --network-configuration "awsvpcConfiguration={subnets=[subnet-XXXXX,subnet-XXXXX],securityGroups=[sg-XXXXX],assignPublicIp=DISABLED}" \
 --scheduling-strategy REPLICA \
 --deployment-controller type=ECS \
 --availability-zone-rebalancing "ENABLED" \
 --deployment-configuration "maximumPercent=200,minimumHealthyPercent=100,deploymentCircuitBreaker={enable=true,rollback=true}" \
 --tags key=Name,value=sample-service \
 --enable-ecs-managed-tags

以上となります。
本投稿が、少しでも皆さんの参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?