Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions samtranslator/feature_toggle/feature_toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/plugins/application/serverless_app_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]))
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions samtranslator/translator/managed_policy_translator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import logging

LOG = logging.getLogger(__name__)


class ManagedPolicyLoader(object):
def __init__(self, iam_client):
self._iam_client = iam_client
self._policy_map = None

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.
Expand All @@ -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