From 53a1fa355aa5323d4a1715bdf1e6d06fd7d03cfb Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Wed, 17 Feb 2021 10:18:44 -0800 Subject: [PATCH] chore: Add logging to boto3.client usage --- samtranslator/feature_toggle/feature_toggle.py | 2 ++ samtranslator/plugins/application/serverless_app_plugin.py | 6 ++++++ samtranslator/translator/managed_policy_translator.py | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/samtranslator/feature_toggle/feature_toggle.py b/samtranslator/feature_toggle/feature_toggle.py index b1dc736e8c..6e665390c0 100644 --- a/samtranslator/feature_toggle/feature_toggle.py +++ b/samtranslator/feature_toggle/feature_toggle.py @@ -108,6 +108,7 @@ class FeatureToggleAppConfigConfigProvider(FeatureToggleConfigProvider): def __init__(self, application_id, environment_id, configuration_profile_id): FeatureToggleConfigProvider.__init__(self) try: + LOG.info("Loading feature toggle config from AppConfig...") # Lambda function has 120 seconds limit # (5 + 25) * 2, 60 seconds maximum timeout duration 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): ) binary_config_string = response["Content"].read() self.feature_toggle_config = json.loads(binary_config_string.decode("utf-8")) + LOG.info("Finished loading feature toggle config from AppConfig.") except Exception as ex: LOG.error("Failed to load config from AppConfig: {}. Using empty config.".format(ex)) # There is chance that AppConfig is not available in a particular region. diff --git a/samtranslator/plugins/application/serverless_app_plugin.py b/samtranslator/plugins/application/serverless_app_plugin.py index c043ceeca9..2f4d9b0e4e 100644 --- a/samtranslator/plugins/application/serverless_app_plugin.py +++ b/samtranslator/plugins/application/serverless_app_plugin.py @@ -156,12 +156,14 @@ def _handle_get_application_request(self, app_id, semver, key, logical_id): :param string key: The dictionary key consisting of (ApplicationId, SemanticVersion) :param string logical_id: the logical_id of this application resource """ + LOG.info("Getting application {}/{} from serverless application repo...".format(app_id, semver)) get_application = lambda app_id, semver: self._sar_client.get_application( ApplicationId=self._sanitize_sar_str_param(app_id), SemanticVersion=self._sanitize_sar_str_param(semver) ) try: self._sar_service_call(get_application, logical_id, app_id, semver) self._applications[key] = {"Available"} + LOG.info("Finished getting application {}/{}.".format(app_id, semver)) except EndpointConnectionError as e: # No internet connection. Don't break verification, but do show a warning. 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): :param string key: The dictionary key consisting of (ApplicationId, SemanticVersion) :param string logical_id: the logical_id of this application resource """ + LOG.info("Requesting to create CFN template {}/{} in serverless application repo...".format(app_id, semver)) create_cfn_template = lambda app_id, semver: self._sar_client.create_cloud_formation_template( ApplicationId=self._sanitize_sar_str_param(app_id), SemanticVersion=self._sanitize_sar_str_param(semver) ) response = self._sar_service_call(create_cfn_template, logical_id, app_id, semver) + LOG.info("Requested to create CFN template {}/{} in serverless application repo.".format(app_id, semver)) self._applications[key] = response[self.TEMPLATE_URL_KEY] if response["Status"] != "ACTIVE": self._in_progress_templates.append((response[self.APPLICATION_ID_KEY], response["TemplateId"])) @@ -293,6 +297,7 @@ def on_after_transform_template(self, template): self._in_progress_templates = [] # Check each resource to make sure it's active + LOG.info("Checking resources in serverless application repo...") for application_id, template_id in temp: get_cfn_template = ( lambda application_id, template_id: self._sar_client.get_cloud_formation_template( @@ -302,6 +307,7 @@ def on_after_transform_template(self, template): ) response = self._sar_service_call(get_cfn_template, application_id, application_id, template_id) self._handle_get_cfn_template_response(response, application_id, template_id) + LOG.info("Finished checking resources in serverless application repo.") # Don't sleep if there are no more templates with PREPARING status if len(self._in_progress_templates) == 0: diff --git a/samtranslator/translator/managed_policy_translator.py b/samtranslator/translator/managed_policy_translator.py index 8621ec21d1..0b5d1f78f0 100644 --- a/samtranslator/translator/managed_policy_translator.py +++ b/samtranslator/translator/managed_policy_translator.py @@ -1,3 +1,8 @@ +import logging + +LOG = logging.getLogger(__name__) + + class ManagedPolicyLoader(object): def __init__(self, iam_client): self._iam_client = iam_client @@ -5,6 +10,7 @@ def __init__(self, iam_client): def load(self): if self._policy_map is None: + LOG.info("Loading policies from IAM...") paginator = self._iam_client.get_paginator("list_policies") # Setting the scope to AWS limits the returned values to only AWS Managed Policies and will # not returned policies owned by any specific account. @@ -15,5 +21,6 @@ def load(self): for page in page_iterator: name_to_arn_map.update(map(lambda x: (x["PolicyName"], x["Arn"]), page["Policies"])) + LOG.info("Finished loading policies from IAM.") self._policy_map = name_to_arn_map return self._policy_map