将 ELB 放入我的 ECS 集群/服务中

将 ELB 放入我的 ECS 集群/服务中

我正在尝试将 ELB 放入我的 ECS 服务中,使用这个Terraform 文件

但应用它时会出现以下错误。您对我错误的设置有什么想法吗?

$ terraform apply ...
aws_ecs_task_definition.beatthemarket-task: Refreshing state... (ID: beatthemarket)
aws_ecs_cluster.default: Refreshing state... (ID: arn:aws:ecs:us-west-1:186598327969:cluster/beatthemarket)
aws_iam_role.beathemarket-role: Refreshing state... (ID: beathemarket-role)
aws_elb.beathemarket-elb: Refreshing state... (ID: beathemarket-elb)
aws_ecs_service.beatthemarket_service: Creating...
  cluster:                                 "" => "arn:aws:ecs:us-west-1:186598327969:cluster/beatthemarket"
  deployment_maximum_percent:              "" => "200"
  deployment_minimum_healthy_percent:      "" => "100"
  desired_count:                           "" => "1"
  iam_role:                                "" => "arn:aws:iam::186598327969:role/beathemarket-role"
  load_balancer.#:                         "" => "1"
  load_balancer.2282006059.container_name: "" => "beatthemarket_service"
  load_balancer.2282006059.container_port: "" => "8080"
  load_balancer.2282006059.elb_name:       "" => "beathemarket-elb"
  name:                                    "" => "beatthemarket-service"
  task_definition:                         "" => "arn:aws:ecs:us-west-1:186598327969:task-definition/beatthemarket:2"
Error applying plan:

1 error(s) occurred:

* aws_ecs_service.beatthemarket_service: InvalidParameterException: The container beatthemarket_service does not exist in the task definition.
    status code: 400, request id: 67ef4ee6-08e8-11e6-9b7a-95aa41386391

答案1

Panagiotis Moustafellos 在#devops工程师slack channel 确实帮我解决了这个问题。结果发现容器beatthemarket_service不存在。(令人困惑的是)这是beatthemarket任务定义名称

所以我刚刚更换

resource "aws_ecs_service" "beatthemarket_service" {
  name            = "beatthemarket-service"
  cluster         = "${aws_ecs_cluster.default.id}"
  task_definition = "${aws_ecs_task_definition.beatthemarket-task.arn}"
  desired_count   = 1
  iam_role = "${aws_iam_role.beatthemarket_role.arn}"
  load_balancer {
    elb_name = "${aws_elb.beathemarket-elb.name}"
    container_name = "beatthemarket_service"
    container_port = 8080
  }
}

resource "aws_ecs_service" "beatthemarket_service" {
  name            = "beatthemarket-service"
  cluster         = "${aws_ecs_cluster.default.id}"
  task_definition = "${aws_ecs_task_definition.beatthemarket-task.arn}"
  desired_count   = 1
  iam_role = "${aws_iam_role.beatthemarket_role.arn}"
  load_balancer {
    elb_name = "${aws_elb.beathemarket-elb.name}"
    container_name = "beatthemarket"
    container_port = 8080
  }
}

相关内容