使用lambda boto3描述侦听器规则计数



我刚刚在Lambda函数和长度函数上使用了下面的代码来计算listner规则。然而,即使ALB有20多个规则,它也总是将值返回为2。

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

得到这样的输出。

Response as 2 

要获取规则,应该使用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

最新更新