Created
July 16, 2026 22:05
-
-
Save rssnyder/de933f910fbc358c8c432cc58dd77ad0 to your computer and use it in GitHub Desktop.
reset a listener rule and target groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Set a listener rule to send 100% of traffic to one target group and | |
| 0% to another target group. | |
| Fill in the three values below and run: python3 set_traffic_weight.py | |
| """ | |
| import boto3 | |
| # ---- INPUT: fill these in ---- | |
| LISTENER_RULE_ARN = "arn:aws:elasticloadbalancing:REGION:ACCOUNT:listener-rule/app/..." | |
| ACTIVE_TARGET_GROUP_ARN = "arn:aws:elasticloadbalancing:REGION:ACCOUNT:targetgroup/active-tg/..." # gets 100% | |
| INACTIVE_TARGET_GROUP_ARN = "arn:aws:elasticloadbalancing:REGION:ACCOUNT:targetgroup/inactive-tg/..." # gets 0% | |
| # -------------------------------- | |
| client = boto3.client("elbv2") | |
| client.modify_rule( | |
| RuleArn=LISTENER_RULE_ARN, | |
| Actions=[ | |
| { | |
| "Type": "forward", | |
| "ForwardConfig": { | |
| "TargetGroups": [ | |
| {"TargetGroupArn": ACTIVE_TARGET_GROUP_ARN, "Weight": 100}, | |
| {"TargetGroupArn": INACTIVE_TARGET_GROUP_ARN, "Weight": 0}, | |
| ] | |
| }, | |
| } | |
| ], | |
| ) | |
| print("Done. 100% -> active TG, 0% -> inactive TG.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment