1

I have created classical load balancer in Amazon Web Services and I have given the listener port as 9090. And I have associated the load balancer with a cluster with 2 EC2 instances. I have given the inbound rules for the instances for 9090 as well.

And in order to create a service in the cluster I have created a task definition as follows.

{
  "family": “my-spring-task“,
  "containerDefinitions": [{
    "image": “my-docker-group/my-spring-app“,
    "name": "my-spring-app",
    "cpu": 10,
    "memory": 256,
    "essential": true,
    "portMappings": [{
      "containerPort": 9090,
      "hostPort": 9090
    }]
  }]
}

Then I create the service, with the above task definition given.

aws ecs register-task-definition --cli-input-json file://service90-task.json

aws ecs create-service --cluster service90-cluster --service-name service90-service --load-balancers loadBalancerName=service90-load-balancer,containerName=my-spring-app,containerPort=9090 --task-definition service90-task  --role ecs-service-role --desired-count 0

My plan is to run a Spring Boot project, which is build with gradle and docker plugin.

I have the project running port 8080. And it is working as expected. But when I try to run a service on port 9090 it doesn't work due to the failing of the health check.

I need advice as to how to make the port to 9090. or any port number.

1 Answers1

2

Most likely the port inside the container is still 8080, unless you reconfigured spring boot itself to use 9090. In that scenario you'll want to set containerPort to 8080 and leave hostPort at 9090.

Alternatively you can leave hostPort blank, and ECS will assign a random 'high' port to each container, then attach that to the ALB. This has the benefit of relieving you of needing to map port assignments in your ECS cluster, and multiple instances of the same container can run on the same host.

Jason Martin
  • 4,865
  • 15
  • 24