ivymatch
ivymatch

Reputation: 149

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://i.sstatic.net/VgE2r.jpg

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

Upvotes: 12

Views: 6101

Answers (3)

Lola Nolan
Lola Nolan

Reputation: 21

For anyone having this issue in the future:

After hours of modifying some heavy-duty settings trying to figure this out - my application in docker-compose was mapping 8080:8000

I changed this to be the same 8000:8000, pushed this new docker image and used this version for fargate cluster instance. The task definition then had 8000:8000 which worked!

Seem to have to be the same ports for host and container in fargate so make sure your application and container ports are the same

Upvotes: 0

Jorangutang
Jorangutang

Reputation: 430

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

Upvotes: 31

Brett Green
Brett Green

Reputation: 3765

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.

Upvotes: 1

Related Questions