8

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:

enter image description here

Can someone please help me to fix this?

3
  • How did you solve this issue? Commented Jan 27, 2022 at 5:49
  • I have similar issue, don't know how to resolve that. I want to switch to EKS immediately :D. Commented Feb 25, 2022 at 10:15
  • I know it is been over 1 year old question but I am going to post the solution anyway The issue is that your load balancer configured with you service is targeting the container on that port. Commented Aug 30, 2022 at 13:15

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

2 Comments

if you add the port mapping to 80, the container is not using 7001?
Does the ALB need to match the 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".
3

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.