Skip to content

Commit

Permalink
fix: initialize the the sar boto3 client only if it's needed (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
keetonian committed Feb 7, 2019
1 parent 16988e4 commit 6b174dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions samtranslator/plugins/application/serverless_app_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def __init__(self, sar_client=None, wait_for_template_active_status=False, valid
super(ServerlessAppPlugin, self).__init__(ServerlessAppPlugin.__name__)
self._applications = {}
self._in_progress_templates = []
if sar_client:
self._sar_client = sar_client
else:
self._sar_client = boto3.client('serverlessrepo')
self._sar_client = sar_client
self._wait_for_template_active_status = wait_for_template_active_status
self._validate_only = validate_only

Expand Down Expand Up @@ -89,6 +86,9 @@ def on_before_transform_template(self, template_dict):
key = (app_id, semver)
if key not in self._applications:
try:
# Lazy initialization of the client- create it when it is needed
if not self._sar_client:
self._sar_client = boto3.client('serverlessrepo')
service_call(app_id, semver, key, logical_id)
except InvalidResourceException as e:
# Catch all InvalidResourceExceptions, raise those in the before_resource_transform target.
Expand Down

0 comments on commit 6b174dd

Please sign in to comment.