Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize aws client init #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sns_lambda_update_ssl_rule/functions/update_ssl_rule.py
Original file line number Diff line number Diff line change
@@ -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(',')
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down