def target_group_attributes()

in application-load-balancer-copy-utility/copy_classic_load_balancer.py [0:0]


def target_group_attributes(alb_data, alb_arn):
    # Create a configuration dict of Target Group attributes
    attributes = {}
    tg_arns = list(alb_data['target_group_arns'])
    for target_group_attribute in alb_data['target_group_attributes']:
        for tg_arn in tg_arns:
            # If target_group_attribute has stickiness_policy
            # Make sure each attribute set matches each target group
            if 'stickiness_policy' in target_group_attribute:
                if 'stickiness' in tg_arn['arn']:
                    if tg_arn['backend_port']==target_group_attribute['TargetGroup_Port']:
                        attributes[tg_arn['arn']] = \
                            [{'Key': 'deregistration_delay.timeout_seconds',
                              'Value': target_group_attribute['dereg_timeout_seconds_delay']},
                            {'Key': 'stickiness.enabled',
                             'Value': target_group_attribute['stickiness.enabled']},
                            {'Key': 'stickiness.type',
                             'Value': target_group_attribute['stickiness.type']},
                            {'Key': 'stickiness.lb_cookie.duration_seconds',
                             'Value': target_group_attribute['stickiness.lb_cookie.duration_seconds']}
                            ]
                        tg_arns.remove(tg_arn)
                        break
            else:
                if tg_arn['backend_port'] == target_group_attribute['TargetGroup_Port']:
                    attributes[tg_arn['arn']] = [{'Key': 'deregistration_delay.timeout_seconds',
                                                'Value': target_group_attribute['dereg_timeout_seconds_delay']}]
                    tg_arns.remove(tg_arn)
                    break

     # Configure Target Group attributes
    for arn in attributes:
        response = client.modify_target_group_attributes(
            TargetGroupArn=arn, Attributes=attributes[arn])
        if debug:
            print("Modify target group attributes response: ")
            pprint(response)
    return