Last Updated on May 15, 2021
Below is a Python Script that gets the price of AWS Elastic Load Balancers (ELB). This can retrieve prices for Classic, Application, Network and Gateway Load Balancers. It can also get the price of load balancers in AWS Outposts. See the different examples of how to use this Python code below.
Output
You can check if the price is correct in the AWS Load Balancer Pricing page.
- Code Explained
- Classic Load Balancer
- Application Load Balancer
- Network Load Balancer
- Gateway Load Balancer
- Load Balancer in AWS Outposts
- Load Balancer Price across all AWS Regions
Code Explained
The get_load_balancer_price
accepts three parameters – region_code, lb_product_family and is_outposts.
region_code
(string) is the target region for the price of the load balancers. It’s in the format of region codes like ap-south-1, us-east-1, eu-west-1.
lb_product_family
(string) is the product family attribute in the AWS Price List API for Elastic Load Balancing (ELB).
The values for lb_product_family
are
- Load Balancer for Classic Load Balancers
- Load Balancer-Application for Application Load Balancers
- Load Balancer-Network for Network Load Balancers
- Load Balancer-Gateway for Gateway Load Balancer
is_outposts
(boolean) is an optional parameter. If this is not set, by default this is set to False or the load balancer price being retrieved is in an AWS region, not in AWS Outposts. If this is set to True, then it will retrieve the price in AWS Outposts.
The output of the get_load_balancer_price function is the price_details
dictionary.
Depending on the type of Load Balancer it will have different key-value pairs.
For Classic Load Balancer price_details
will have the following keys.
LoadBalancerUsage
the hourly price of Classic Load BalancerDataProcessing-Bytes
the per GB price of data processed
For new generation of Load Balancers like Application, Network and Gateway Load Balancers, including the ones in AWS Outposts, price_details
will have the following keys.
LoadBalancerUsage
the hourly price of the load balancersLCUUsage
the LCU-hour price (or partial hour)
For more information on LCU Usage please visit the Elastic Load Balancer pricing page.
Examples on how to use the Python Script to retrieve Elastic Load Balancer (ELB) prices
On the examples below we will only use the main part of the python script to show how to use the get_load_balancer_price
for different types of AWS Load Balancers.
Classic Load Balancer
For Classic Load Balancers the lb_product_family
must be set to Load Balancer.
Output
Application Load Balancer
For Application Load Balancers the lb_product_family
must be set to Load Balancer-Application.
Output
Network Load Balancer
For Network Load Balancers the lb_product_family
must be set to Load Balancer-Network.
Output
Gateway Load Balancer
For Gateway Load Balancers the lb_product_family
must be set to Load Balancer-Gateway.
Output
AWS Outposts Application Load Balancers
For Load Balancers that are in AWS Outposts, the lb_product_family
will still be the same depending on your target type of Load Balancer.
This time, we have to set the is_outposts
parameter to True
.
Output
Listing Load Balancer Price for All Regions
Below is a code to get the price of Application Load Balancers in the all AWS regions. It uses the listing of AWS regions using Boto3.
Output. Fixed the formatting for easier reading.
First column is the Load Balancer Usage price.
Second column is the LCU Usage price.
I hope the above helps in getting the price of AWS Elastic Load Balancers (ELB).