0

I have a ASP.NET Core 5 Web app and an API(Asp.NET Core API). I want to run these two application in one Fargate Task. I am an absolute beginner in container and AWS Fargate world. So based on my R&D came up with following 4 step solution:

  1. Will create a Task definition which will have two container definitions and each will have its own exposed container port by defining portMappings. lets say port 49153 for Web and 49155 for API container.

  2. Will create two target group with target type IP and with desired ports. Lets assume target1(port-49153) and target2 (port-49155).

  3. Will create a service and add two load balancers in this service like:

    "loadBalancers":[
    {  
      "targetGroupArn":"target1Arn",
      "containerName":"webapp",
      "containerPort":49153
    },
    {  
      "targetGroupArn":"target2Arn",
      "containerName":"webapi",
      "containerPort":49155
    } ]
    
  4. Will route incoming traffic to specific target in the ALB listeners.

I tried to implement this solution but failed as the ports exposed in task definition are not getting hit somehow. (I am no expert, so if the above solution is not as it should be then please suggest the appropriate one)

What I defined in above points is my end goal but for the simplicity I tired exposing a specific port with single container in Task definition but failed with this too. I done this in following ways:

  1. Published my container image to ECR with AWS tool kit for Visual Studio 2019. the Docker file looks like:

  2. Created new Task definition with uploaded container image and 49153 as containerPort in portMappings.

  3. Created target group "Target49153" with target type IP and with port 49153.

  4. Created new Service with name "SRVC" with this Task Definition. enter image description here

  5. Security Group, my service attached with, is having following inbound rules. enter image description here

After doing these, my service is failing with the error message service SRVC (port 49153) is unhealthy in target-group Target49153 due to (reason Request timed out). when I try to access the app with Task's public IP like "http://taskpublicip:49153" it gives "ERR_CONNECTION_REFUSED". however when I edit Security Group of my service and add inbound rule for All traffic from anywhere, the application works at port 80 like "http://taskpublicip". but not able to hit port 49153 in anyway. Please help me to find out the right way. Thanks!

Vikas Dagar
  • 143
  • 1
  • 1
  • 10
  • It sounds like the actual process running in the Docker container is listening on port 80, not 49153. How about including your Task JSON definition in the question? – Mark B Jun 02 '21 at 20:37
  • @MarkB the JSON is very big to post in question itself. Any specific tag you want to check from that JSON? for port mapping it has :"portMappings": [ { "hostPort": 49153, "protocol": "tcp", "containerPort": 49153 } ], – Vikas Dagar Jun 02 '21 at 20:51
  • Why are you trying to map port `49153` if your application inside the container is listening on port `80`? – Mark B Jun 02 '21 at 21:09
  • @MarkB as I mentioned in question that my end goal is to run two application on same task that's why I need to expose different port. Also if you see the docker file the port exposed for the container is 49153 then why the application is running on port 80? am i doing something wrong while creating the docker container from Visual Studio? – Vikas Dagar Jun 03 '21 at 03:23
  • It seems you have just picked a random port to expose in Docker, without actually modifying the software running in the container to attach to that port. – Mark B Jun 03 '21 at 12:18

0 Answers0