From 149e8b8b7812cb2ecb0d058cac540760f7a76e0a Mon Sep 17 00:00:00 2001 From: "Leonardo Zavala (Leo)" Date: Thu, 5 Mar 2020 14:51:32 -0800 Subject: [PATCH 1/2] Some actions may not be ForwardConfig. --- .../functions/update_ssl_rule.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py b/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py index e97f0f52..59a8f908 100644 --- a/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py +++ b/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py @@ -69,12 +69,14 @@ def get_current_http_target_group(http_listener_rules, arr_available_target_grou actions = http_listener_rules[i]['Actions'] n=0 - while n Date: Thu, 30 Apr 2020 15:19:10 -0700 Subject: [PATCH 2/2] Apparantly this initializing the client outside the function speeds up loading from cache. --- .../functions/update_ssl_rule.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py b/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py index 59a8f908..5f47ca4d 100644 --- a/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py +++ b/sns_lambda_update_ssl_rule/functions/update_ssl_rule.py @@ -1,11 +1,14 @@ import os import json, boto3 +region = os.environ['REGION'] +elbv2_client = boto3.client('elbv2', region_name=region) +codedeploy_client = boto3.client('codedeploy', region_name=region) + def lambda_handler(event, context): print("Trigger Event: ") print(event) - region = os.environ['REGION'] - elbv2_client = boto3.client('elbv2', region_name=region) + available_target_groups = os.environ['AVAILABLE_TARGET_GROUPS'] arr_available_target_groups = available_target_groups.split(',') @@ -46,7 +49,7 @@ def lambda_handler(event, context): if modify==1: print("Updating SSL listener rules..") rule_arn = https_listener_rules[i]['RuleArn'] - results[rule_arn] = modify_rules(elbv2_client, rule_arn, actions) + results[rule_arn] = modify_rules(rule_arn, actions) i +=1 @@ -110,7 +113,7 @@ def check_target_update(old_target_group, arr_available_target_groups): # Sends notification to CodeDeploy on hook status... def send_codedeploy_validation_status(event, results): region = os.environ['REGION'] - codedeploy_client = boto3.client('codedeploy', region_name=region) + status = ('Failed', 'Succeeded')[len(results) > 0] print(status) @@ -126,7 +129,7 @@ def send_codedeploy_validation_status(event, results): return False -def modify_rules(elbv2_client, arn, actions): +def modify_rules(arn, actions): try: return elbv2_client.modify_rule( RuleArn=arn,