From fce214f3537edc714ee84f6e37058be7c7310c04 Mon Sep 17 00:00:00 2001 From: PeyGis Date: Tue, 4 Jul 2023 15:52:53 +0000 Subject: [PATCH] add tags, listeners and attributes to elb handler --- .../aws/resources/load_balancer_handler.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lambda_function/aws/resources/load_balancer_handler.py b/lambda_function/aws/resources/load_balancer_handler.py index 7c98cf7..b2cb757 100644 --- a/lambda_function/aws/resources/load_balancer_handler.py +++ b/lambda_function/aws/resources/load_balancer_handler.py @@ -60,9 +60,21 @@ def handle_single_resource_item(self, region, elb_name, action_type="upsert"): # Create a Boto3 client for the Elastic Load Balancing service aws_elbv2_client = boto3.client('elbv2') response = aws_elbv2_client.describe_load_balancers(Names=[elb_name]) - # Extract load balancer details from the response load_balancer_obj = response['LoadBalancers'][0] + load_balancer_arn = load_balancer_obj["LoadBalancerArn"] + + ## Fetch the attributes attached to the load balancer + elb_attributes_response = aws_elbv2_client.describe_load_balancer_attributes(LoadBalancerArn=load_balancer_arn) + load_balancer_obj["Attributes"] = elb_attributes_response["Attributes"] + + ## Fetch the listeners attatched to this load balancer + elb_listeners_response = aws_elbv2_client.describe_listeners(LoadBalancerArn=load_balancer_arn) + load_balancer_obj["Listeners"] = elb_listeners_response["Listeners"] + + ## Fetch the tags attached to this load balancer + elb_tags_response = aws_elbv2_client.describe_tags(ResourceArns=[load_balancer_arn]) + load_balancer_obj["Tags"] = elb_tags_response["TagDescriptions"][0]["Tags"] # Handles unserializable date properties in the JSON by turning them into a string load_balancer_obj = json.loads(json.dumps(load_balancer_obj, default=str))