def _process_api_events(self, function, api_events, template, condition=None):
for logicalId, event in api_events.items():<EOL><INDENT>event_properties = event.get("<STR_LIT>", {})<EOL>if not event_properties:<EOL><INDENT>continue<EOL><DEDENT>self._add_implicit_api_id_if_necessary(event_properties)<EOL>api_id = self._get_api_id(event_properties)<EOL>try:<EOL><INDENT>path = event_properties["<STR_LIT>"]<EOL>method = event_properties["<STR_LIT>"]<EOL><DEDENT>except KeyError as e:<EOL><INDENT>raise InvalidEventException(logicalId, "<STR_LIT>".format(e))<EOL><DEDENT>if (not isinstance(path, six.string_types)):<EOL><INDENT>raise InvalidEventException(logicalId,<EOL>"<STR_LIT>")<EOL><DEDENT>if (not isinstance(method, six.string_types)):<EOL><INDENT>raise InvalidEventException(logicalId,<EOL>"<STR_LIT>")<EOL><DEDENT>api_dict = self.api_conditions.setdefault(api_id, {})<EOL>method_conditions = api_dict.setdefault(path, {})<EOL>method_conditions[method] = condition<EOL>self._add_api_to_swagger(logicalId, event_properties, template)<EOL>api_events[logicalId] = event<EOL><DEDENT>function.properties["<STR_LIT>"].update(api_events)<EOL>
Actually process given API events. Iteratively adds the APIs to Swagger JSON in the respective Serverless::Api
resource from the template

:param SamResource function: SAM Function containing the API events to be processed
:param dict api_events: API Events extracted from the function. These events will be processed
:param SamTemplate template: SAM Template where Serverless::Api resources can be found
:param str condition: optional; this is the condition that is on the function with the API event