Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Describe listener rule count using lambda boto3

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 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading