Docker compose ECS集成:负载均衡器是应用程序类型,项目需要网络

Joh*_*ton 4 amazon-web-services amazon-ecs amazon-elb aws-cloudformation docker-compose

我有一个docker-compose.yml文件如下:

version: "3.8"
x-aws-loadbalancer: "arn:aws:elasticloadbalancing:my-load-balancer"
services:
  fastapi:
    image: username/auth:FastAPI
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: FastAPI
    ports:
      - "5555:5555"
  nginx:
    image: username/auth:nginx
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: nginx
    ports:
      - "80:80"
    depends_on:
      - fastapi
networks:
  default:
    external: true
    name: my-sg
Run Code Online (Sandbox Code Playgroud)

但是当尝试使用 ECS 将其集成时,docker compose up我收到错误:

load balancer "arn:aws:elasticloadbalancing:my-load-balancer" is of type application, project require a network
Run Code Online (Sandbox Code Playgroud)

我还尝试使用顶级x-aws-vpc属性提供 vpc 并收到相同的错误。

什么

Mar*_*k B 5

这是因为您正在使用 port 5555,docker-compose 无法知道该端口正在用于 HTTP,因此它假设您需要网络负载均衡器,因为应用程序负载均衡器仅支持 HTTP。

根据ECS docker-compose 集成的文档

如果 Compose 文件中的服务仅公开端口 80 或 443,则会创建应用程序负载均衡器,否则 ECS 集成将配置网络负载均衡器。使用不同端口的 HTTP 服务可以通过在端口声明中使用 x-aws-protocol 自定义扩展声明 http 协议来强制使用 ALB:

因此,按照我链接的文档中的示例,我会尝试将 FastAPI 服务声明更改为以下内容:

  fastapi:
    image: username/auth:FastAPI
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: FastAPI
    ports:
      - "5555:5555"
        x-aws-protocol: http
Run Code Online (Sandbox Code Playgroud)

或者可以将其更改为以下内容,以更紧密地匹配文档中的示例:

ports:
  - target: 5555
    x-aws-protocol: http
Run Code Online (Sandbox Code Playgroud)