Last active
May 18, 2020 16:39
-
-
Save kevit/a2d2a8186eab33b9867776807352c7ff to your computer and use it in GitHub Desktop.
This file contains 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
elbv2_response = boto3.client("elbv2") | |
if elbv2_response is not None: | |
v2_load_balancers = elbv2_response.describe_load_balancers() | |
else: | |
v2_load_balancers = None | |
##not implemented rules | |
rules = get_alb_rules(listener_arn) | |
def get_alb_rules(alb, listener_arn): | |
listener = boto3.client('elbv2') | |
response = listener.describe_listeners( | |
LoadBalancerArn = listener_arn | |
) | |
for Rule in response["Rules"]: | |
try: | |
data = {} | |
data['path-pattern'] = Rule['Conditions'][0]['Values'] | |
data['host-header'] = Rule['Conditions'][1]['Values'] | |
data['priority'] = Rule['Priority'] | |
print(json.dumps(data, indent=4)) | |
except: | |
print('Reached end of Rules') | |
return data | |
instance_to_v2_load_balancer_map = {} | |
if v2_load_balancers is not None: | |
for elbv2_lb in v2_load_balancers["LoadBalancers"]: | |
load_balancer_arn = elbv2_lb['LoadBalancerArn'] | |
load_balancer_name = elbv2_lb["LoadBalancerName"] | |
target_groups = elbv2_response.describe_target_groups( | |
LoadBalancerArn=load_balancer_arn | |
) | |
if target_groups is None: | |
continue | |
for target_group in target_groups["TargetGroups"]: | |
target_group_arn = target_group['TargetGroupArn'] | |
target_healths = elbv2_response.describe_target_health( | |
TargetGroupArn=target_group_arn | |
) | |
if target_healths is None: | |
continue | |
for target_health in target_healths["TargetHealthDescriptions"]: | |
instance_to_v2_load_balancer_map[target_health["Target"]["Id"]] = load_balancer_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment