Use AWS Load Balancer several times - amazon-web-services

Currently we have a loadbalancer where a listener listens on https and then escorts to a target group where our ec2 windows instance is the target.
Now we have another ec2 instance (linux). The should be accessible via another subdomain. Do I need a new load balancer (which costs money..) or can I use one and split the targets somehow?

You didn't specify which type of Load Balancer you are using? If you are using ALB (application load balancer) you can configure "Host conditions" to route to different domains.
Based on AWS ALB documentation:
You can use host conditions to define rules that forward requests to different target groups based on the host name in the host header (also known as host-based routing). This enables you to support multiple domains using a single load balancer.
If you are using classic ELB, you need different load balancers to support different domains.

Related

What's the difference between a load balancer and target group in AWS?

I'm following along a course and I don't really get the difference between an aws load balancer and an aws target group. The course kinda talks about them interchangeably. Does an aws target group include an aws load balancer? What's the theoretical and practical difference?
In AWS, a load balancer is an actual server (or cluster of servers) managed entirely by Amazon that accepts incoming traffic and routes the traffic across multiple backend servers, thus distributing the load.
A target group is simply a list of target servers that the load balancer should distribute the load to.
You configure the load balancer by telling it to send all traffic that matches a certain pattern (like all traffic that comes in on a certain port, or all traffic that is for a certain domain name) to a specific target group.
Load Balancer - AWS thing..
Target Group - your thing.
Target group is collection of your own servers ( one or more than one server)..
Load balancer help to distribute incoming traffic (API Request etc.) to these different target groups based on rules and listeners.
You need to assign DNS/domain name to load balancer, all incoming traffic first comes to this then it distribute to target groups servers..

2 ports for frontend and backend. How many load balancers required and how to configure them in gcp

In gcp I have created 2 template groups one for backend which internally contains 2 instances and other for frontend with 2 instances. Frontend(https) works on port 8081 and backend on port 8444. So how should I configure load balancer for both
You probably want to use a combination of load balancers, one for external HTTPS traffic and another internal load balancer for your backend traffic. This is a common pattern in multi-tier web design. See "External Versus Internal Load Balancing" for more details and examples.
Create a forwarding rule [1] to direct network traffic to another load balancer
[1]https://cloud.google.com/sdk/gcloud/reference/compute/forwarding-rules/create

Point domains to springboot app. running in different ports inside a ec2 instance

I have 2 hosted zone defined in route53: domain1.com, domain2.com, and 2 springBoot app running inside a ec2 instance but in different ports.
I would like to know if it is possible to point domain1.com to app1 and domain2.com to app2
Yes, this is possible.
You have two options: one using a classic load balancer, the other using the Application Load balancer.
You would need two classic load balancers, one for each domain. Then you would associate the appropriate listener / port to each load balancer.
With the Application load balancer, you have the option of doing host-based routing, so you would only need one. You would have two target groups, one for each instance/port combination.

Routing Traffic to different instance using ELB

I have a website hosted on Site Ground let's say www.test.com
I create a subdomain xyz.test.com and routed the traffic to a backend server A through a load balancer which is hosted in a privated subnet in a VPC. It works fine since I have create a listener on which forwards the traffic from 443 to 3000. Now I want to add one backend server B in the same private subnet and want the traffic hitting port 444 of the ELB to be routed to this server.I want the requests xyz.test.com:444 to go to to port 3010 of the server B. In short I want to route traffic to different instances behind a load balancer but my URL is the same just the ports are different.
How can I achieve this?
You want to setup an Application Load Balancer. From the documentation (emphasis mine):
A load balancer serves as the single point of contact for clients. The load balancer distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This increases the availability of your application. You add one or more listeners to your load balancer.
A listener checks for connection requests from clients, using the protocol and port that you configure, and forwards requests to one or more target groups, based on the rules that you define. Each rule specifies a target group, condition, and priority. When the condition is met, the traffic is forwarded to the target group. You must define a default rule for each listener, and you can add rules that specify different target groups based on the content of the request (also known as content-based routing).
Some of the benefits that may interested you, over a Classic Load Balancer are:
Support for path-based routing. You can configure rules for your
listener that forward requests based on the URL in the request. This
enables you to structure your application as smaller services, and
route requests to the correct service based on the content of the URL.
Support for host-based routing. You can configure rules for your listener that forward requests based on the host field in the HTTP
header. This enables you to route requests to multiple domains using a
single load balancer.
Support for routing requests to multiple applications on a single EC2 instance. You can register each instance or IP address with the
same target group using multiple ports.
Support for registering targets by IP address, including targets outside the VPC for the load balancer.

Amazon Application Load Balancer Host Based Routing to a specific ECS Container Service

I'm new to ECS & ALB in AWS's universe, and i'd like to know how can i point my App in the front end to a specific ECS service.
Should I give it maybe the :port or /service_name ?
and if i'd like to use Host-Based Routing, and i use my own DNS subdomains.
For Example :
<service>.hostname.com ,
How can i point each service to it's corresponding one in the ECS cluster through the Application Load Balancer ?
With Amazon's Application Load Balancer, you associate your services with Target Groups. You can then create rules on your listeners that say which traffic to send to which Target Group. Application Load Balancer supports two different rule types: Host (eg: service1.hostname.com) and Path (eg: /service1).
So the basic things you need to do are:
Create a target group for each service
Create a rule sending the hosts/paths you want to the target group
Associate each service with its associated target group