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

发布于 2025-01-17 15:29:42 字数 482 浏览 2 评论 0原文

我只是在 Lambda 函数和长度函数上使用下面的代码来计算监听器规则。然而,即使 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 

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2025-01-24 15:29:42

获取规则,您应该使用 描述规则

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文