Home > Net >  Describe listener rule count using lambda boto3
Describe listener rule count using lambda boto3

Time:03-29

I just used below code on Lambda function and length function to calculate listner rules. However it always return the value as 2 even ALB has more than 20 rules.

import json
import boto3
    
def lambda_handler(event, context):
    client = boto3.client('elbv2')
    response1 = client.describe_listeners(
    ListenerArns=[
        'arn:aws:elasticloadbalancing:eu-west-2:account_id:listener/app/my_load_balancer_listener',
         ],
    )
    tot = len(response1)
    return response1

Get the output like this.

Response as 2 

CodePudding user response:

The get the rules, you should use describe_rules:

def lambda_handler(event, context):
    client = boto3.client('elbv2')
    response1 = client.describe_rules(
    ListenerArn='arn:aws:elasticloadbalancing:eu-west-2:account_id:listener/app/my_load_balancer_listener',
    )
    tot = len(response1['Rules'])
    return tot
  • Related