'Task running in Fargate is not found with public IP address

I'm creating a simple Spring API, which has a get call that returns some data. I put this in a docker container and tested the container on my localhost and it works (localhost:8080/getbooks returns a list of books). I then pushed this container to ECR and am running it on Fargate using a task.

My task is listed as RUNNING on a cluster in Fargate. However, when I try to access it via its public IP address (34.208.216.217:8080/getbooks), the request times out.

I've tried adding the port 8080 to the security group when creating the task (allowing everyone to access it), but this hasn't fixed anything.

Here's a picture of my task details, where I'm getting the public IP from: https://imgur.com/a/WccLJH7

I expect the running task to be accessible via the listed public IP, but it is not.



Solution 1:[1]

Try modifying the application settings to something like:

server.address=0.0.0.0

And relaunch the task. The task is starting but probably bound to localhost which won't work under Fargate. 0.0.0.0 will tell it to bind to any ip address.

Solution 2:[2]

Answer for those still having this issue. The reason I was having this issue: You need to ensure that your container port is mapped to a host port correctly and that you have listed the host port in the security group. Fargate seems to default map your host port to be the same as your container port and makes the custom TCP port in the security group port 80. Simple Solution:

  1. Go to your task definition revision that you are running on Fargate, then on the JSON tab you will see a section on Port Mappings that lists your Container and Host port. Copy the port number of the host port.
  2. Go to the security group of your running task, at the top right of the inbound rules you are able to edit them. Add two custom TCP's, one for source '0.0.0.0/0' and another for '::/0', past the port number you copied above into the port section of each new inbound rule. Save this.
  3. Access your App on the public IP using 'HTTP' not 'HTTPS', forward to the host port and you should see your application

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brett Green
Solution 2 Jorangutang