I have a ecs cluster and have some services running, and I needed to update the container port from 80 to 7001.
So I tried creating a new revision of the task definition but I get the below error:
Can someone please help me to fix this?
I have a ecs cluster and have some services running, and I needed to update the container port from 80 to 7001.
So I tried creating a new revision of the task definition but I get the below error:
Can someone please help me to fix this?
You are getting this error because the load balancer associated with the ECS service is targeting the container on port 80 while your container is not exposing port 80. In order to resolve this you have two options
Solution #1
In your task definition file (json file) you need to add the port mapping to allow traffic to your container on port 80.
"portMappings": [ { "containerPort": 80, "hostPort": 80, "protocol": "tcp" } ], Solution #2
Update the load balancer associated with your ECS service to target the container on the specified port which is in your case 7001
Please note: Load balancing settings can only be set on service creation. This means you have to re-create the service
portMappings.containerPort or portMappings.hostPort? I figured the ALB needs to point to the port exposed on the host (which forwards ingress to the correct container port anyway). Yet, {"containerPort": 3000, "hostPort": 80, "protocol": "tcp"} fails for me with "The container XXX did not have a container port 80 defined".I've been able to resolve this by:
removing the load-balancer assigned to the service first,
revise the container ports on the task-definition,
update the service to use the new task-definition revision,
then re-assigning the load balancer to the service with the updated info.
aws ecs update-service
--cluster [cluster-name]
--service [service-name]
--load-balancers "[]"
Provided above is the aws cli command to remove all associated load balancers.
aws ecs update-service \ --cluster ss-business-locator-cluster \ --service ss-business-locator-service \ --load-balancers "[{\"containerName\": \"[Replace with container name]\", \"containerPort\":[replace with container port], \"targetGroupArn\": \"[Replace with target-group arn]\"}]" This worked for me. Good luck with your project and cheers to my first stack overflow post.