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
}
]
}
}
]
)