0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

albでweight変更しよう

0
Last updated at Posted at 2026-02-28

ALBでweightを変更しよう

どうも現在は「modify_listener」を使う必要あるみたい

事前準備

1 ロールに「ElasticLoadBalancingFullAccess」を付ける

2 ALBを作成し、1つのリスナーに対してターゲットグループを2つ紐づける

変更前:ターゲットグループ qweを重み:100 wer:0

変更後:ターゲットグループ qweを重み:0 wer:100

import boto3

client = boto3.client('ec2')

def lambda_handler(event, context):
    client  = boto3.client('elbv2')
    client.modify_listener(
        ListenerArn = "arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:listener/app/zzzz/a07da323e1c67afa/bac026fed2c40891",
        DefaultActions = [
            {
              'Type': 'forward',
              'ForwardConfig':{
                'TargetGroups':[
                  {
                    'TargetGroupArn' : 'arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:targetgroup/qwe/478b2c244664c4b7',
                    'Weight'         : 0
                  },
                  {
                    'TargetGroupArn' : 'arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:targetgroup/wer/e77498cef2fc6ba9',
                    'Weight'         : 100
                  }
                ]
              }
            }
         ]
    )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?