I have a docker-compose.yml
file as follows:
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
But when attempting to integrate this with ECS using docker compose up
I receive the error:
load balancer "arn:aws:elasticloadbalancing:my-load-balancer" is of type application, project require a network
I have also tried providing a vpc using the top-level x-aws-vpc
property and received the same error.
What
CodePudding user response:
It's because you are using port 5555
, which docker-compose can't know is being uses for HTTP, so it makes the assumption that you need a network load balancer since Application Load Balancers only support HTTP.
Per the documentation for ECS docker-compose integration:
If services in the Compose file only expose ports 80 or 443, an Application Load Balancer is created, otherwise ECS integration will provision a Network Load Balancer. HTTP services using distinct ports can force use of an ALB by claiming the http protocol with x-aws-protocol custom extension within the port declaration:
So, just going by that example at the documentation I linked, I would try changing your FastAPI service declaration to the following:
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
Or maybe change it to the following, to more closely match the example in the documentation:
ports:
- target: 5555
x-aws-protocol: http