Beispiel #1
0
    def start(self):
        """
        Creates and starts the Local Lambda Invoke service. This method will block until the service is stopped
        manually using an interrupt. After the service is started, callers can make HTTP requests to the endpoint
        to invoke the Lambda function and receive a response.

        NOTE: This is a blocking call that will not return until the thread is interrupted with SIGINT/SIGTERM
        """

        # We care about passing only stderr to the Service and not stdout because stdout from Docker container
        # contains the response to the API which is sent out as HTTP response. Only stderr needs to be printed
        # to the console or a log file. stderr from Docker container contains runtime logs and output of print
        # statements from the Lambda function
        service = LocalLambdaInvokeService(lambda_runner=self.lambda_runner,
                                           port=self.port,
                                           host=self.host,
                                           stderr=self.stderr_stream)

        service.create()

        LOG.info(
            "Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template"
            " through the endpoint.")

        service.run()
    def test_create_service_endpoints(self, flask_mock, error_handling_mock):
        app_mock = Mock()
        flask_mock.return_value = app_mock

        error_handling_mock.return_value = Mock()

        lambda_runner_mock = Mock()
        service = LocalLambdaInvokeService(lambda_runner=lambda_runner_mock, port=3000, host='localhost')

        service.create()

        app_mock.add_url_rule.assert_called_once_with('/2015-03-31/functions/<function_name>/invocations',
                                                      endpoint='/2015-03-31/functions/<function_name>/invocations',
                                                      view_func=service._invoke_request_handler,
                                                      methods=['POST'],
                                                      provide_automatic_options=False)
    def test_create_service_endpoints(self, flask_mock, error_handling_mock):
        app_mock = Mock()
        flask_mock.return_value = app_mock

        error_handling_mock.return_value = Mock()

        lambda_runner_mock = Mock()
        service = LocalLambdaInvokeService(lambda_runner=lambda_runner_mock, port=3000, host='localhost')

        service.create()

        app_mock.add_url_rule.assert_called_once_with('/2015-03-31/functions/<function_name>/invocations',
                                                      endpoint='/2015-03-31/functions/<function_name>/invocations',
                                                      view_func=service._invoke_request_handler,
                                                      methods=['POST'],
                                                      provide_automatic_options=False)
    def start(self):
        """
        Creates and starts the Local Lambda Invoke service. This method will block until the service is stopped
        manually using an interrupt. After the service is started, callers can make HTTP requests to the endpoint
        to invoke the Lambda function and receive a response.

        NOTE: This is a blocking call that will not return until the thread is interrupted with SIGINT/SIGTERM
        """

        # We care about passing only stderr to the Service and not stdout because stdout from Docker container
        # contains the response to the API which is sent out as HTTP response. Only stderr needs to be printed
        # to the console or a log file. stderr from Docker container contains runtime logs and output of print
        # statements from the Lambda function
        service = LocalLambdaInvokeService(lambda_runner=self.lambda_runner,
                                           port=self.port,
                                           host=self.host,
                                           stderr=self.stderr_stream)

        service.create()

        LOG.info("Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template"
                 " through the endpoint.")

        service.run()