I can able to get the load balancers using below
import boto3
elb = boto3.client('elbv2')
lbs = elb.describe_load_balancers()
How to get the instances of the lbs
.
Also How Can I fetch the load balancers which state is not active as describe_load_balanacers only give state active
load balanceres.
Network Load Balancer currently supports 200 targets per Availability Zone. For example, if you are in two AZs, you can have up to 400 targets registered with Network Load Balancer. If cross-zone load balancing is on, then the maximum targets reduce from 200 per AZ to 200 per load balancer.
Boto3 is the name of the Python SDK for AWS. It allows you to directly create, update, and delete AWS resources from your Python scripts.
Classic Load Balancer
Use: client = boto3.client('elb')
Then describe_load_balancers()
results include a list of instances:
'Instances': [
{
'InstanceId': 'string'
},
],
Application Load Balancer
Use: client = boto3.client('elbv2')
describe_target_groups()
passing in the Load Balancer ARN to obtain a list of Target Groups associated with the Load Balancerdescribe_target_health()
to obtain a list of targets (instances).Here is a sample response:
{
'TargetHealthDescriptions': [
{
'Target': {
'Id': 'i-0f76fade',
'Port': 80,
},
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With