Skip to content

Commit 6b174dd

Browse files
committed
fix: initialize the the sar boto3 client only if it's needed (#697)
1 parent 16988e4 commit 6b174dd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

samtranslator/plugins/application/serverless_app_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ def __init__(self, sar_client=None, wait_for_template_active_status=False, valid
4848
super(ServerlessAppPlugin, self).__init__(ServerlessAppPlugin.__name__)
4949
self._applications = {}
5050
self._in_progress_templates = []
51-
if sar_client:
52-
self._sar_client = sar_client
53-
else:
54-
self._sar_client = boto3.client('serverlessrepo')
51+
self._sar_client = sar_client
5552
self._wait_for_template_active_status = wait_for_template_active_status
5653
self._validate_only = validate_only
5754

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

0 commit comments

Comments
 (0)