code: def resources_to_link(self, resources):
          
  
          rest_api_id = self.RestApiId
          if isinstance(rest_api_id, dict) and "Ref" in rest_api_id:
              rest_api_id = rest_api_id["Ref"]
  
          # If RestApiId is a resource in the same template, then we try find the StageName by following the reference
          # Otherwise we default to a wildcard. This stage name is solely used to construct the permission to
          # allow this stage to invoke the Lambda function. If we are unable to resolve the stage name, we will
          # simply permit all stages to invoke this Lambda function
          # This hack is necessary because customers could use !ImportValue, !Ref or other intrinsic functions which
          # can be sometimes impossible to resolve (ie. when it has cross-stack references)
          permitted_stage = "*"
          stage_suffix = "AllStages"
          explicit_api = None
          if isinstance(rest_api_id, string_types):
  
              if rest_api_id in resources \
                 and "Properties" in resources[rest_api_id] \
                 and "StageName" in resources[rest_api_id]["Properties"]:
  
                  explicit_api = resources[rest_api_id]["Properties"]
                  permitted_stage = explicit_api["StageName"]
  
                  # Stage could be a intrinsic, in which case leave the suffix to default value
                  if isinstance(permitted_stage, string_types):
                      if not permitted_stage:
                          raise InvalidResourceException(rest_api_id, 'StageName cannot be empty.')
                      stage_suffix = permitted_stage
                  else:
                      stage_suffix = "Stage"
  
              else:
                  # RestApiId is a string, not an intrinsic, but we did not find a valid API resource for this ID
                  raise InvalidEventException(self.relative_id, "RestApiId property of Api event must reference a valid "
                                                                "resource in the same template.")
  
          return {
              'explicit_api': explicit_api,
              'explicit_api_stage': {
                  'permitted_stage': permitted_stage,
                  'suffix': stage_suffix
              }
          }
docs: If this API Event Source refers to an explicit API resource, resolve the reference and grab
          necessary data from the explicit API