<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_cloudformation(self, **kwargs):
 """Returns the Lambda EventSourceMapping to which this pull event corresponds. Adds the appropriate managed policy to the function's execution role, if such a role is provided. :param dict kwargs: a dict containing the execution role generated for the function :returns: a list of vanilla CloudFormation Resources, to which this pull event expands :rtype: list """

        function = kwargs.get('function')

        if not function:
            raise TypeError("Missing required keyword argument: function")

        resources = []

        lambda_eventsourcemapping = LambdaEventSourceMapping(self.logical_id)
        resources.append(lambda_eventsourcemapping)

        try:
            # Name will not be available for Alias resources
            function_name_or_arn = function.get_runtime_attr("name")
        except NotImplementedError:
            function_name_or_arn = function.get_runtime_attr("arn")

        if not self.Stream and not self.Queue:
            raise InvalidEventException(
                self.relative_id, "No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided.")

        if self.Stream and not self.StartingPosition:
            raise InvalidEventException(
                self.relative_id, "StartingPosition is required for Kinesis and DynamoDB.")

        lambda_eventsourcemapping.FunctionName = function_name_or_arn
        lambda_eventsourcemapping.EventSourceArn = self.Stream or self.Queue
        lambda_eventsourcemapping.StartingPosition = self.StartingPosition
        lambda_eventsourcemapping.BatchSize = self.BatchSize
        lambda_eventsourcemapping.Enabled = self.Enabled
        if 'Condition' in function.resource_attributes:
            lambda_eventsourcemapping.set_resource_attribute('Condition', function.resource_attributes['Condition'])

        if 'role' in kwargs:
            self._link_policy(kwargs['role'])

        return resources