Can an internal load balancer be deployed to one subnet? (AWS Cloud) - amazon-web-services

I see AWS Cloud load balancers in 2 categories:
By Traffic - Internet and Internal LBs
By Use - Application, Network and CLassic LBs
I want to deploy an internal load balancer into one private subnet and ask it to only distribute traffic among the instances in that subnet.
Is that possible?
I know that application LBs must be deployed to 2 subnets. Is there a configuration that allows deployment to only one subnet?

I know that application LBs must be deployed to 2 subnets. Is there a configuration that allows deployment to only one subnet?
Unfortunately, not for ALB.
However, you can use 1 subnet with NLB and CLB.

Related

Network load balancer in single AZ, Application load balancer & ec2 in multiple with cross zone issues

I have an elastic beanstalk application which has an ALB and ec2 instances that can be created in any of the 6 AZ's based on the auto scaling policy.
I then put an NLB in front to create a single static IP which seems to work fine as long as at least 1 ec2 instance exists in the same AZ that the NLB lives. If ec2 instances exist only in other AZ's the health check is timing out and the routing isn't working from the NLB anymore. Is the below a possible configuration?
Create Security Group/s that allow traffic between ALB and EC2.
Create SG for EC2 instance to allow traffic from SG

Why you need to specify subnets in Application Load Balancer?

I'll start with describing the architecture of Application Load Balancer:
We have the Application Load Balancer, which contains a list of one or more listeners. Each listener is associated with one specific port and protocol, so that traffic incoming to the load balancer with this port will be handled by this listener. Then, each listener holds a list of rules. A rule specify conditions and actions - basically where to route traffic to. A listener also must have a default action which will be taken if no other condition is met. Usually, this action will be to route traffic to a specific target group.
A target group is a group of either EC2 instances, IP addresses, other Application Load Balancer, or Lambda function.
Furthermore, when you create an Application Load Balancer, it asks you to specify a VPC and list of 2 or more Availability zones, and for each to specify a subnet.
My question now is: Why does AWS asks you to specify this? As far as I understand, the target groups and the registered targets are where you specify the backend of the load balancer, so why do we need to specify the subnets in the ALB configuration?
EDIT
After experimenting, I found that, if I have a EC2 instance running a web server in AZ 3 for example, and now I create a load balancer and selects AZs 1 and 2, then traffic will not reach the web server on AZ 3 until I add another AZ in the load balancer settings.
So if to accurate my question: If this setting of AZs in the load balancer settings means: these are the AZs in which the Load Balancer will send traffic to, in what scenario should I not choose ALL the availability zones there are?
An Application Load Balancer runs on Amazon EC2 infrastructure. Think of it as an Amazon EC2 instance with pre-loaded software, but you don't actually see the EC2 instance in your own account.
Instead, you will see the Network Interfaces where the Load Balancer connects into the network.
Traffic will come into your network through an Internet Gateway then route within the VPC to the Load Balancer. The Load Balancer will then determine a target to receive the traffic, and will send the request via the Network Interface to the resource in the VPC.
When such traffic flows through the VPC, it is subject to normal Security Groups and Network Access Control Lists (NACLs). Private IP addresses will be assigned for each Network Interface used by the Load Balancer.
The Load Balancer instance runs in multiple AZs. If one AZ has a failure, then the Load Balancer instance in the remaining AZ(s) will continue to run. This is why the Load Balancer wants a connection to the VPC in multiple subnets.
Bottom line: While you might normally think of the Load Balancer as a "blackbox service", it is still just some software running on a virtualized computer that needs logical connectivity to the VPC, and it obeys all the rules of networking within the VPC.
why do we need to specify the subnets in the ALB configuration?
Because the load balancer itself requires physical network interfaces, which are created in the subnets you specify (one network interface per subnet).
When you need ALB you must assign an IP address to it. A subnet is nothing more than a range of IP addresses. By placing an ALB inside a subnet, you define which range of IP you desire to be assigned to this resource. Moreover, These subnets allow you to configure different security layers regards the resource inside the subnet for traffic management.
Your target group is located in another subnet with a different range, whereas you can place your ALB in another subnet with a different range.

Multi-Zone Load Balancing with Elastic Beanstalk and NAT

I have been trying to set up Elastic Beanstalk so that all instances across multiple availability zones appear externally to have the same static IP address. To do that, I followed the instructions here:
https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-static-IP-address/
I also followed the prerequisites here:
https://aws.amazon.com/premiumsupport/knowledge-center/nat-gateway-vpc-private-subnet/
I created a demo environment (PHP) and installed the sample application - just for a proof of concept. Everything works fine as long as I use only a single availability zone (load balancer is in a public subnet and there are two other private subnets for each instance - but all are in the same availability zone). The moment I try to modify Elastic Beanstalk so that some of the instances are in a different availability zone, I have mixed results. Sometimes I am able to get the application to load in my browser, and other times it just times out. I have tried various combinations of enabling / disabling cross zone load balancing, and I get the same results either way.
When I look at the load balancer, all instances show "In Service", and Elastic Beanstalk reports a status of "OK". When I run the VPC Reachability analyzer, it shows that each instances is reachable from the Internet Gateway.
Here is the configuration I have set up:
Availability Zone us-east-1c
Subnet 1 (public): This subnet routes traffic to the Internet Gateway. This is the subnet where the load balancer resides.
Subnet 2 (private): This subnet does not route anything to the Internet Gateway. Instead, it routes all outbound traffic to the NAT (which also resides in the public subnet).
Subnet 3 (private): This subnet is identical to Subnet 2 (uses the same routing table).
Availability Zone us-east-1b
Subnet 4 (private): This subnet is identical to Subnet 2 (uses the same routing table).
Availability Zone us-east-1d
Subnet 5 (private): This subnet is identical to Subnet 2.
So what I am seeing is that as long as I deploy instances only to subnets 2 and 3, everything works fine. As soon as I try to add instances in subnets 4 or 5, that's when the application starts becoming intermittent. Sometimes it works and sometimes it doesn't.
I should also point out that I am trying to load this application in my browser by referencing the URL of the load balancer, and also the auto-generated Elastic Beanstalk URL for the environment. The behavior is the same in both cases.
What am I doing wrong?
I was able to solve this by creating a public subnet in each availability zone and deploying the load balancer to each of those public subnets. After that, everything worked.

Stitching together AWS API Gateway and Private EC2 Instances

I've spent the majority of today reading google results and documentation on how to connect AWS API Gateway to EC2 instances (created by Elastic Beanstalk) in a private subnet. I know that API Gateway requires targets to be publicly addressable, so...
I manually created an Application Elastic Load Balancer that listens for (and terminates) HTTPS at a public IP address;
I created a VPC with two subnets: one public (holds load balancer) and one private (holds EC2 instances); and,
I believe I have to create security groups that allow everyone/everywhere to connect to the load balancer, but only entities in my public subnet to connect to my EC2 instances.
Unfortunately I'm unable to view the sample Beanstalk application via the load balancer's DNS name. The connection just times-out.
Can someone please confirm I've identified all the steps? Is there any way I can trace my requests to see where they're failing? Or (even better) why they're failing? Thanks!
Check your security groups to make sure that HTTPS traffic is allowed
Make sure your Network ACLs are allowing traffic from your load balance to your EC2 instances
Check your VPC routes to ensure there is a route from your load balancer to your EC2 instance

AWS - ELB Availability Zones + VPC best practices?

When setting up an ELB, it would say the following:
You must specify subnets from at least two Availability Zones to increase the availability of your load balancer.
I currently have two VPCs:
WebVPC
public-subnet-us-east-1a
private-subnet-us-east-1b
DatabaseVPC
public-subnet-us-east-1a
private-subnet-us-east-1b
The ELB is only meant for the WebVPC (to serve web traffic). I currently only have one public and one private subnet per VPC, which means I can only provide the ELB with one public subnet from my WebVPC.
Does this mean it is best practice to have at least two public and at least two private subnets?
Your architecture is not Highly Available. It is best practice to replicate services across multiple Availability Zones (AZs) in case there is a failure in one AZ (effectively, if a data center fails).
Also, it is typically best to keep all related services for an application in the same VPC unless you have a particular reason to keep them separate.
Also, security is improved by putting your application in private subnets, with only your load balancer in the public subnets.
Therefore, the recommended architecture would be:
One VPC
A public subnet in AZ-a
A public subnet in AZ-b
A load balancer connected to both public subnets
A private subnet in AZ-a
A private subnet in AZ-b
Your web application running simultaneously in both private subnets (assuming that it can run on multiple Amazon EC2 instances)
Your database running in one of the private subnets, with the ability to fail-over to the other private subnet. Amazon RDS can do this automatically with the Multi-AZ option (additional charges apply).
To learn more about architecting highly scalable solutions, I recommend the ARC201: Scaling Up to Your First 10 Million Users session from the AWS re:Invent conference in 2016 (YouTube, SlideShare, Podcast).
Yes. It is best practice to provide at least two Availability Zones.
If EC2 Instances were launched in Private subnet then load balancer should be launched in Public subnet which should have internet gateway attached to it.
Load Balancer can handle traffic through internet gateway and redirect to Private IPs of EC2 Instances. Only registered EC2 Instances will receive traffic from Load Balancer.
In your case:
You have to launch Database in Private subnet not in Public subnet as per best practice. Both Web tier and database tier can be in same VPC. If you have different environment like Dev, Test and Prod - all should be launch in different VPC. You can use VPC Peering to connect VPCs.
Instead of launching EC2 Instances in Public subnet, it is good to launch in Private subnet. Because, You will be using Load balancer to redirect network traffic to EC2 Instances.