Reputation: 1794
I am trying to get the list of listener rules based on a filter as described here: https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html
Below is my command:
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'
when I run it I keep getting:
Unknown options: --filters, TargetGroupArn==
Upvotes: 1
Views: 2456
Reputation: 11
Try something like:
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
you'll get the RuleArn in text format. Without the grep, you will get something like:
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 removes the unwanted lines.
Upvotes: 1
Reputation: 1178
Adiii is correct to point out that the filter option isn't supported here, however, as the query option is always available, you can get what you want from it, TargetGroupArn
included.
So with some digging in JEMSPath, the basic solution is:
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'
Upvotes: 2
Reputation: 60074
If you want to get a list of listener rule you can use query, is there any need of filter with query?
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]}'
This will return all rule under listener and will return host and priority.
{
"Priority": "1",
"Host": "test.example.com"
}
or to get Just ARN of rule
aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-east-1:34555433333:listener/app/ApplicationLoadBalancer/a333ddsdsddsds/22assds3dasfd --query 'Rules[].RuleArn'
As aws elbv2 describe-rules
does not have an option for the filter that is why you got 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>]
So workaround can list all the rule and grep your desired target group which is attached to rule.
aws elbv2 describe-rules --listener-arn arn:aws:elasticloadbalancing:us-west-2:060558051165:listener/app/Prod-Main-Delaers/11a84cfee3fc1e29/37fb4adb7314bac0 | grep -A6 -B6 targetgroupARN
Upvotes: 2