Load balancers help optimize server speed and improve network performance by sending requests to available servers, but when they're not in use, they become an unnecessary expense.
AWS load balancers must be able to connect with healthy, available targets to facilitate a reliable cloud-based network. If you want to save on your cloud platform bill, you should regularly find any load balancers that have no target attached to them and remove them so that you're not paying for more than you need.
In this article, we'll briefly explain the differences between each load balancer type, then show you two ways to find and remove any that are unneeded.
AWS Elastic Load Balancer Types
Elastic Load Balancers (ELBs) distribute traffic across multiple targets, sending requests only to servers that are healthy enough to perform the required function. There are three types of ELBs, namely:
- Application Load Balancers (ALBs), which route requests at the application layer (HTTP/HTTPS), and support path-based routing
- Network Load Balancers (NLBs), which route requests at the transport layer (TCP/SSL) using a flow hash algorithm, enabling them to handle millions of requests per second
- Classic Load Balancers (CLBs), which require a fixed relationship between the load balancer port and container port, meaning that your cluster needs a container instance for each port.
Regardless of what type of load balancers you are using, they all need valid targets to function. Here are some of the reasons that a load balancer could end up without a target:
- The targets are in an availability zone (AZ) that’s not enabled
- A security group is blocking the traffic
- A network access control list (ACL) is blocking the traffic
- A target is present but has not passed a health check, so no requests are sent
Removing AWS ELBs With No Target
You can remove any type of elastic load balancer using the AWS console. Location, auditing, and deletion can all also be done through the AWS command line interface (CLI), so we'll examine both methods here.
Locating Load Balancers with No Target
To identify load balancers with no target through the AWS console, perform the following steps:
- Sign in to the AWS management console.
- Go to the EC2 dashboard.
- Select Load Balancing from the navigation panel.
- Under Load Balancing, select Load Balancers.
- Click on the load balancer you wish to examine.
- Click on the Description tab in the bottom panel.
- Under Status, if the reading says "0 out of 0 instances in service,” then there are no backend instances currently in use. This means that the load balancer can safely be removed.
Alternatively, you may use the AWS CLI for Linux, OSX, or Unix, and perform the following steps:
- Run the “describe-load-balancers” command to determine if any backend instances connected to your load balancer are currently in progress.
- The instance IDs attached to the load balancer will be the output, so if the list is empty, the load balancer is currently vacant. That means it can safely be removed.
Here is an example of the command:
Once you run the command, look over the output attributes. If you don’t see an “InstanceID” listed in the “Instances” array, then the load balancer doesn't have a target.
Deleting Unused Load Balancers
Once you have identified a load balancer without a target, you can now delete it using either of these two methods:
You can do this through the AWS console by taking the following steps:
- If you have a CNAME record for your domain that points to your load balancer, point it elsewhere first. Allow the DNS change to complete before deletion.
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation pane, under LOAD BALANCING, choose Load Balancers.
- Select the load balancer you wish to delete.
- Select Actions, then select Delete.
- When prompted for confirmation, choose Yes, Delete.
If using the AWS CLI to delete load balancers, simply use the “delete-load-balancer” command and use the Amazon Resource Name (ARN) to specify which load balancer you want to delete.
Automating Checks for AWS ELBs with No Target Using Blink
If you are using ELBs and want to run this type of check often, there’s a better way than manually running through these steps.
When you create a free Blink account, you can schedule automated checks like this one to run regularly so you get the benefit without the context-switching.
Get started and create your free Blink account today.