Skip to content

Commit 1170f78

Browse files
authored
chore: Add logging to boto3.client usage (#1932)
1 parent 848c39c commit 1170f78

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

samtranslator/feature_toggle/feature_toggle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class FeatureToggleAppConfigConfigProvider(FeatureToggleConfigProvider):
108108
def __init__(self, application_id, environment_id, configuration_profile_id):
109109
FeatureToggleConfigProvider.__init__(self)
110110
try:
111+
LOG.info("Loading feature toggle config from AppConfig...")
111112
# Lambda function has 120 seconds limit
112113
# (5 + 25) * 2, 60 seconds maximum timeout duration
113114
client_config = Config(connect_timeout=5, read_timeout=25, retries={"total_max_attempts": 2})
@@ -120,6 +121,7 @@ def __init__(self, application_id, environment_id, configuration_profile_id):
120121
)
121122
binary_config_string = response["Content"].read()
122123
self.feature_toggle_config = json.loads(binary_config_string.decode("utf-8"))
124+
LOG.info("Finished loading feature toggle config from AppConfig.")
123125
except Exception as ex:
124126
LOG.error("Failed to load config from AppConfig: {}. Using empty config.".format(ex))
125127
# There is chance that AppConfig is not available in a particular region.

samtranslator/plugins/application/serverless_app_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ def _handle_get_application_request(self, app_id, semver, key, logical_id):
156156
:param string key: The dictionary key consisting of (ApplicationId, SemanticVersion)
157157
:param string logical_id: the logical_id of this application resource
158158
"""
159+
LOG.info("Getting application {}/{} from serverless application repo...".format(app_id, semver))
159160
get_application = lambda app_id, semver: self._sar_client.get_application(
160161
ApplicationId=self._sanitize_sar_str_param(app_id), SemanticVersion=self._sanitize_sar_str_param(semver)
161162
)
162163
try:
163164
self._sar_service_call(get_application, logical_id, app_id, semver)
164165
self._applications[key] = {"Available"}
166+
LOG.info("Finished getting application {}/{}.".format(app_id, semver))
165167
except EndpointConnectionError as e:
166168
# No internet connection. Don't break verification, but do show a warning.
167169
warning_message = "{}. Unable to verify access to {}/{}.".format(e, app_id, semver)
@@ -177,10 +179,12 @@ def _handle_create_cfn_template_request(self, app_id, semver, key, logical_id):
177179
:param string key: The dictionary key consisting of (ApplicationId, SemanticVersion)
178180
:param string logical_id: the logical_id of this application resource
179181
"""
182+
LOG.info("Requesting to create CFN template {}/{} in serverless application repo...".format(app_id, semver))
180183
create_cfn_template = lambda app_id, semver: self._sar_client.create_cloud_formation_template(
181184
ApplicationId=self._sanitize_sar_str_param(app_id), SemanticVersion=self._sanitize_sar_str_param(semver)
182185
)
183186
response = self._sar_service_call(create_cfn_template, logical_id, app_id, semver)
187+
LOG.info("Requested to create CFN template {}/{} in serverless application repo.".format(app_id, semver))
184188
self._applications[key] = response[self.TEMPLATE_URL_KEY]
185189
if response["Status"] != "ACTIVE":
186190
self._in_progress_templates.append((response[self.APPLICATION_ID_KEY], response["TemplateId"]))
@@ -293,6 +297,7 @@ def on_after_transform_template(self, template):
293297
self._in_progress_templates = []
294298

295299
# Check each resource to make sure it's active
300+
LOG.info("Checking resources in serverless application repo...")
296301
for application_id, template_id in temp:
297302
get_cfn_template = (
298303
lambda application_id, template_id: self._sar_client.get_cloud_formation_template(
@@ -302,6 +307,7 @@ def on_after_transform_template(self, template):
302307
)
303308
response = self._sar_service_call(get_cfn_template, application_id, application_id, template_id)
304309
self._handle_get_cfn_template_response(response, application_id, template_id)
310+
LOG.info("Finished checking resources in serverless application repo.")
305311

306312
# Don't sleep if there are no more templates with PREPARING status
307313
if len(self._in_progress_templates) == 0:

samtranslator/translator/managed_policy_translator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import logging
2+
3+
LOG = logging.getLogger(__name__)
4+
5+
16
class ManagedPolicyLoader(object):
27
def __init__(self, iam_client):
38
self._iam_client = iam_client
49
self._policy_map = None
510

611
def load(self):
712
if self._policy_map is None:
13+
LOG.info("Loading policies from IAM...")
814
paginator = self._iam_client.get_paginator("list_policies")
915
# Setting the scope to AWS limits the returned values to only AWS Managed Policies and will
1016
# not returned policies owned by any specific account.
@@ -15,5 +21,6 @@ def load(self):
1521
for page in page_iterator:
1622
name_to_arn_map.update(map(lambda x: (x["PolicyName"], x["Arn"]), page["Policies"]))
1723

24+
LOG.info("Finished loading policies from IAM.")
1825
self._policy_map = name_to_arn_map
1926
return self._policy_map

0 commit comments

Comments
 (0)