def test_initalize_with_values(self):
     lambda_runner = Mock()
     local_service = LocalApigwService(Api(), lambda_runner, static_dir="dir/static", port=5000, host="129.0.0.0")
     self.assertEqual(local_service.port, 5000)
     self.assertEqual(local_service.host, "129.0.0.0")
     self.assertEqual(local_service.api.routes, [])
     self.assertEqual(local_service.static_dir, "dir/static")
     self.assertEqual(local_service.lambda_runner, lambda_runner)
 def test_initalize_with_values(self):
     lambda_runner = Mock()
     local_service = LocalApigwService([], lambda_runner, static_dir='dir/static', port=5000, host='129.0.0.0')
     self.assertEquals(local_service.port, 5000)
     self.assertEquals(local_service.host, '129.0.0.0')
     self.assertEquals(local_service.routing_list, [])
     self.assertEquals(local_service.static_dir, 'dir/static')
     self.assertEquals(local_service.lambda_runner, lambda_runner)
    def setUp(self):
        self.function_name = Mock()
        self.api_gateway_route = Route(methods=["GET"], function_name=self.function_name, path="/")
        self.list_of_routes = [self.api_gateway_route]

        self.lambda_runner = Mock()
        self.lambda_runner.is_debugging.return_value = False

        self.stderr = Mock()
        self.api = Api(routes=self.list_of_routes)
        self.service = LocalApigwService(self.api, self.lambda_runner, port=3000, host="127.0.0.1", stderr=self.stderr)
Exemple #4
0
    def setUp(self):
        self.function_name = Mock()
        self.api_gateway_route = Route(['GET'], self.function_name, '/')
        self.list_of_routes = [self.api_gateway_route]

        self.lambda_runner = Mock()
        self.lambda_runner.is_debugging.return_value = False

        self.stderr = Mock()
        self.service = LocalApigwService(self.list_of_routes,
                                         self.lambda_runner,
                                         port=3000,
                                         host='127.0.0.1',
                                         stderr=self.stderr)
    def test_create_creates_dict_of_routes(self):
        function_name_1 = Mock()
        function_name_2 = Mock()
        api_gateway_route_1 = Route(methods=["GET"], function_name=function_name_1, path="/")
        api_gateway_route_2 = Route(methods=["POST"], function_name=function_name_2, path="/")

        list_of_routes = [api_gateway_route_1, api_gateway_route_2]

        lambda_runner = Mock()

        api = Api(routes=list_of_routes)
        service = LocalApigwService(api, lambda_runner)

        service.create()

        self.assertEqual(service._dict_of_routes, {"/:GET": api_gateway_route_1, "/:POST": api_gateway_route_2})
    def test_create_creates_dict_of_routes(self):
        function_name_1 = Mock()
        function_name_2 = Mock()
        api_gateway_route_1 = Route(['GET'], function_name_1, '/')
        api_gateway_route_2 = Route(['POST'], function_name_2, '/')

        list_of_routes = [api_gateway_route_1, api_gateway_route_2]

        lambda_runner = Mock()

        service = LocalApigwService(list_of_routes, lambda_runner)

        service.create()

        self.assertEquals(service._dict_of_routes, {'/:GET': api_gateway_route_1,
                                                    '/:POST': api_gateway_route_2
                                                    })
Exemple #7
0
    def start(self):
        """
        Creates and starts the local API Gateway 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
        """

        if not self.api_provider.api.routes:
            raise NoApisDefined("No APIs available in template")

        static_dir_path = self._make_static_dir_path(self.cwd, self.static_dir)

        # 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 = LocalApigwService(
            api=self.api_provider.api,
            lambda_runner=self.lambda_runner,
            static_dir=static_dir_path,
            port=self.port,
            host=self.host,
            stderr=self.stderr_stream,
        )

        service.create()

        # Print out the list of routes that will be mounted
        self._print_routes(self.api_provider.api.routes, self.host, self.port)
        LOG.info(
            "You can now browse to the above endpoints to invoke your functions. "
            "You do not need to restart/reload SAM CLI while working on your functions, "
            "changes will be reflected instantly/automatically. You only need to restart "
            "SAM CLI if you update your AWS SAM template"
        )

        service.run()