Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify AWS ALB traffic distribution using AWS CLI

I have an AWS ALB with a listener configured where default action is to forward traffic in active-active mode : 50% of traffic to a target group (TargetGroupA) and 50% to another target group (TargetGroupB).

To perfom maintenance, I would like to edit this rule using AWS CLI to :

  • change the traffic distribution percentage from 50-50 to 100% on TargetGroupA
  • change the traffic distribution percentage from 100% on TargetGroupA to 100% on TargetGroupB
  • Put back the 50-50 on both target groups
like image 562
Nicolas Pepinster Avatar asked Jul 21 '26 13:07

Nicolas Pepinster


2 Answers

It looks like you should use modify-listener.

The --default-actions parameter has a ForwardConfig.TargetGroups.Weight setting that ranges from 0 to 999.

Use weights like 1,0, 1,1 (50% each) and 0,1 to direct traffic to the target groups.

like image 82
John Rotenstein Avatar answered Jul 23 '26 05:07

John Rotenstein


Using the link given by @john-rotenstein, this command worked for me (with aws-cli/1.18.37):

aws elbv2 modify-listener \
--listener-arn "<listener arn>" \
--default-actions \ 
  '[{
      "Type": "forward",
      "Order": 1,
      "ForwardConfig": {
        "TargetGroups": [
            {"TargetGroupArn": "<target group 1 arn>", "Weight": 1 },
            {"TargetGroupArn": "<target group 2 arn>", "Weight": 0 }
        ]
      }
   }]'
like image 27
Nicolas Pepinster Avatar answered Jul 23 '26 05:07

Nicolas Pepinster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!