code: def on_before_transform_template(self, template_dict):
          
          template = SamTemplate(template_dict)
          intrinsic_resolvers = self._get_intrinsic_resolvers(template_dict.get('Mappings', {}))
  
          service_call = None
          if self._validate_only:
              service_call = self._handle_get_application_request
          else:
              service_call = self._handle_create_cfn_template_request
          for logical_id, app in template.iterate(SamResourceType.Application.value):
              if not self._can_process_application(app):
                  # Handle these cases in the on_before_transform_resource event
                  continue
  
              app_id = self._replace_value(app.properties[self.LOCATION_KEY],
                                           self.APPLICATION_ID_KEY, intrinsic_resolvers)
  
              semver = self._replace_value(app.properties[self.LOCATION_KEY],
                                           self.SEMANTIC_VERSION_KEY, intrinsic_resolvers)
  
              if isinstance(app_id, dict) or isinstance(semver, dict):
                  key = (json.dumps(app_id), json.dumps(semver))
                  self._applications[key] = False
                  continue
  
              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.
                      self._applications[key] = e
docs: Hook method that gets called before the SAM template is processed.
          The template has passed the validation and is guaranteed to contain a non-empty "Resources" section.
  
          This plugin needs to run as soon as possible to allow some time for templates to become available.
          This verifies that the user has access to all specified applications.
  
          :param dict template_dict: Dictionary of the SAM template
          :return: Nothing