AWS CLI:无法过滤描述规则

时间:2019-09-11 06:49:35

标签: amazon-web-services powershell aws-cli

我正在尝试根据此处所述的过滤器获取侦听器规则列表:https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html

下面是我的命令:

aws elbv2 describe-rules \
--listener-arn arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd \
--filters "TargetGroupArn==arn:aws:elasticloadbalancing:us-east-1:34555433333:targetgroup/TG-Test-111111111/ass22dss2dkk" \
--query 'Rules[].RuleArn'

当我运行它时,我不断得到: Unknown options: --filters, TargetGroupArn==

3 个答案:

答案 0 :(得分:1)

如果要获取可以使用查询的侦听器规则列表,是否需要对查询进行过滤?

aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd --query 'Rules[].{Priority:Priority,Host:Conditions[0].Values[0]}'

这将返回侦听器下的所有规则,并返回主机和优先级。

  {
        "Priority": "1",
        "Host": "test.example.com"
  }

或获得规则的Just ARN

aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd --query 'Rules[].RuleArn'

由于aws elbv2 describe-rules没有用于过滤器的选项,因此您获得了Unknown options: --filters

  describe-rules
[--listener-arn <value>]
[--rule-arns <value>]
[--page-size <value>]
[--cli-input-json <value>]
[--starting-token <value>]
[--max-items <value>]
[--generate-cli-skeleton <value>]

describe-rules

因此,解决方法可以列出所有规则,并grep附加到该规则的所需目标组。

aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-west-2:060558051165:listener/app/Prod-Main-Delaers/11a84cfee3fc1e29/37fb4adb7314bac0 | grep -A6 -B6 targetgroupARN

答案 1 :(得分:1)

Adiii正确地指出此处不支持过滤器选项,但是,由于查询选项始终可用,因此您可以从中获得所需的内容,包括TargetGroupArn

因此,通过深入研究JEMSPath,基本解决方案是:

aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd --query 'Rules[].{RuleArn: RuleArn, Actions: Actions[?TargetGroupArn==`arn:aws:elasticloadbalancing:us-east-1:34555433333:targetgroup/TG-Test-111111111/ass22dss2dkk`]}|[].RuleArn'

答案 2 :(得分:0)

尝试类似:

aws elbv2 describe-rules --listener-arn 'arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd' \
  --output text \
  --query "Rules[].{RuleArn: RuleArn, Actions:Actions[?TargetGroupArn=='$targetGroupArn'].TargetGroupArn }" | grep -B 1 ACTIONS | grep -v ACTIONS

您将获得文本格式的 RuleArn。 如果没有 grep,你会得到类似的东西:

arn:aws:elasticloadbalancing:us-east-1:34555433333:listener-rule/app/loadbalancer/a333ddsdsddsds/22assds3dasfd/22assds3dasfs
ACTIONS arn:aws:elasticloadbalancing:us-east-1:34555433333:targetgroup/tg/34555433333

grep 删除不需要的行。