Terraform 应用错误并显示一条消息:更新 ECS 服务 InvalidParameterException:负载均衡器最多可以有 5 个项目

问题描述 投票:0回答:1

我有一个 AWS ALB,它应该前端是一个用 Angular 编写的 ECS Fargate 前端应用程序和一个用 NestJS 编写的后端。我打算对前端和后端使用单个 ALB,因此,我设置了一个侦听器规则,该规则应采用大约 7 个后端条件规则,这些规则是路径模式。

当我尝试部署此应用程序时遇到的错误是:-

updating ECS Service InvalidParameterException: load balancers can have at most 5 items.
我知道 AWS 文档中的限制约为 100 个项目。

我有这个 Terraform 代码,应该配置基础设施:-

resource "aws_ecs_service" "ecs_service_def" {
  name            = "backend-service"
  task_definition = "${aws_ecs_task_definition.ecs_task_def.family}"
  desired_count   = 1
  force_new_deployment = true
  health_check_grace_period_seconds  = 300
  launch_type     = "FARGATE"
  cluster         = data.aws_ecs_cluster.this.id
  depends_on      = [
    aws_iam_role_policy.ecs_service_role_policy,
    data.aws_alb_listener.selected443
  ]
  deployment_circuit_breaker {
    enable = true
    rollback = true
  }
  network_configuration {
    security_groups = ["sg-0233333337779"]
    subnets         = var.db_subnet_ids
  }

  load_balancer {
    target_group_arn = aws_alb_target_group.upload.arn
    container_name   = "backend"
    container_port   = "3000"
  }

  load_balancer {
    target_group_arn = aws_alb_target_group.search-logs.arn
    container_name   = "backend"
    container_port   = "3000"
  }

  load_balancer {
    target_group_arn = aws_alb_target_group.log-file-info.arn
    container_name   = "backend"
    container_port   = "3000"
  }


  dynamic "load_balancer" {
    for_each = local.ecs_load_balancers
    content {
      container_name   = load_balancer.value.container_name
      container_port   = load_balancer.value.container_port
      target_group_arn = load_balancer.value.target_group_arn
    }
  }   
}

locals {
  ecs_load_balancers = [
  {
    container_name   = "backend"
    container_port   = "3000"
    target_group_arn = aws_alb_target_group.download.arn
  },
  {
    container_name   = "backend"
    container_port   = "3000"
    target_group_arn = aws_alb_target_group.update-log-status.arn
  },
  {
    container_name   = "backend"
    container_port   = "3000"
    target_group_arn = aws_alb_target_group.log-upload-info.arn
  },
  {
    container_name   = "backend"
    container_port   = "3000"
    target_group_arn = aws_alb_target_group.recent-logs.arn
  }]
}

我正在使用动态块来配置剩余的规则,但无论我对 Terraform 逻辑进行什么更改,“应用”操作总是会错误地显示给定的消息。

如果有人可以分享此问题的解决方案,我们将不胜感激。

terraform amazon-ecs terraform-provider-aws aws-application-load-balancer
1个回答
0
投票

来自 使用 Amazon ECS 服务注册多个目标组

  • 对于使用应用程序负载均衡器或网络负载均衡器的服务,您不能将超过五个目标组附加到服务。
© www.soinside.com 2019 - 2024. All rights reserved.