Changing AWS ALB Listener's default rule via AWS CLI
Asked Answered
N

1

6

As mentioned in the title, I'd like to change the default rule of a listener for an ALB using AWS CLI. In particular, I want to change which Target Group is used. The desired result should be switching the target ARN inside the action field. This is possible using the AWS console quite easily by editing the action field. Console allows this by removing the default value (the one set at the time of creation), but AWS CLI does not, for some reason. What I've tried is using the following command:

aws elbv2 modify-rule  --actions Type=forward,ForwardConfig={TargetGroups={TargetGroupArn=$TARGET_GROUP_ARN}}
--rule-arn $RULE_ARN

Which returns the following:

An error occurred (OperationNotPermitted) when calling the ModifyRule operation: Default rule '$RULE_ARN' cannot be modified

Does anyone have any idea what I'm doing wrong? The describe command returns a JSON that contains the information that's proportional to the one I'm trying to modify.

Nares answered 10/12, 2020 at 16:56 Comment(0)
N
4

I've managed to find the solution. The rule needs to be modified by editing the listener in question, instead of the default rule itself. The command is the following one:

aws elbv2 modify-listener --listener-arn $LISTENER_ARN --default-actions Type=forward,TargetGroupArn=$TARGET_GROUP_ARN,ForwardConfig={TargetGroups={TargetGroupArn=$TARGET_GROUP_ARN}}

The documentation didn't help much, but the aws elbv2 modify-rule help command did help. I somehow missed it on my first reading. It says the following: To modify the actions for the default rule, use ModifyListener.

Nares answered 14/12, 2020 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.