I want to deploy the angular, and spring boot applications on AWS fargate, I have added two containers for the angular and spring boot application. I have created one task for both containers But wanted to know how can do I communicate to my backend from angular without IP. I know to call with IP but I prefer not to do it that way as the IP change every time. Is there any way?
Kindly help
CodePudding user response:
This answer is based on my high level knowledge of ECS and how AWS Tasks work, and the following documentation: https://aws.amazon.com/blogs/compute/task-networking-in-aws-fargate/
In your case, you have created 2 tasks. They can communicate by IP, but if you do not want to use an IP, then you need to register a DNS and only if necessary a Load Balancer.
You could also look at Service Discovery which is part of ECS: https://aws.amazon.com/blogs/aws/amazon-ecs-service-discovery/
OR, You could re-architect your solution so you have your pair of (Backend Frontend) as 2 containers within 1 Fargate Task. They will communicate through localhost then. This is called Container (local) networking
In Fargate, when you launch multiple containers as part of a single task, they can also communicate with each other over the local loopback interface. Fargate uses a special container networking mode called awsvpc, which gives all the containers in a task a shared elastic network interface to use for communication.
Determine whether you should use local task networking
Local task networking is ideal for communicating between containers that are tightly coupled and require maximum networking performance between them. However, when you deploy one or more containers as part of the same task they are always deployed together so it removes the ability to independently scale different types of workload up and down.
CodePudding user response:
You need to add an Application Load Balancer, and configure your ECS Service to register tasks with the load balancer. Then you would use the address of the load balancer for your API calls from Angular to your backend.