1
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?

More than 5 years have passed since last update.

[AWS] ALB Target Groupの登録解除遅延をpythonで一括で変更

Last updated at Posted at 2018-06-29

解除遅延が未設定では300秒になっており、
リリースの際ALBから切り離すのを待つのが地味につらいため、60秒に一括で変更したかった。
Management Consoleからポチポチ変更しても良かったが、面倒なのでスクリプトで。

import boto3

timeout_seconds = 60

elbv2 = boto3.client('elbv2')
target_groups = elbv2.describe_target_groups()['TargetGroups']
for target_group in target_groups:
  print('# ' + target_group['TargetGroupName'])

  attr = elbv2.describe_target_group_attributes(TargetGroupArn=target_group['TargetGroupArn'])['Attributes']

  now_timeout_seconds = filter(lambda x: x['Key'] == 'deregistration_delay.timeout_seconds', attr)[0]['Value']
  if int(now_timeout_seconds) > timeout_seconds:
    print('modify deregistration_delay timeout_seconds')
    elbv2.modify_target_group_attributes(
      TargetGroupArn=target_group['TargetGroupArn'],
      Attributes=[{
        'Key': 'deregistration_delay.timeout_seconds',
        'Value': str(timeout_seconds)
      }]
    )
  else :
    print('not change: ' + now_timeout_seconds)

属性の変更ならこの部分を変更すれば大体行けるはず
filter(lambda x: x['Key'] == ${変更したい属性}, attr)[0]['Value']

使い捨てスクリプトだが、似たようなことをまたやるだろうからメモ

1
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
1
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?