def setUpClass(cls): cls.code_abs_path_for_throw_error = nodejs_lambda(THROW_ERROR_LAMBDA) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd_for_throw_error = os.path.dirname(cls.code_abs_path_for_throw_error) cls.code_uri_for_throw_error = os.path.relpath(cls.code_abs_path_for_throw_error, cls.cwd_for_throw_error) # Get relative path with respect to CWD cls.code_abs_path = nodejs_lambda(HELLO_FROM_LAMBDA) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd = os.path.dirname(cls.code_abs_path) cls.code_uri = os.path.relpath(cls.code_abs_path, cls.cwd) # Get relative path with respect to CWD cls.hello_world_function_name = "HelloWorld" cls.hello_world_function = provider.Function(name=cls.hello_world_function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri, environment=None, rolearn=None, layers=[]) cls.throw_error_function_name = "ThrowError" cls.throw_error_function = provider.Function(name=cls.throw_error_function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri_for_throw_error, environment=None, rolearn=None, layers=[]) cls.mock_function_provider = Mock() cls.mock_function_provider.get.side_effect = cls.mocked_function_provider cls.service, cls.port, cls.url, cls.scheme = make_service(cls.mock_function_provider, cls.cwd) cls.service.create() t = threading.Thread(name='thread', target=cls.service.run, args=()) t.setDaemon(True) t.start() time.sleep(1)
def setUp(self): self.code_dir = { "echo": nodejs_lambda(ECHO_CODE), "sleep": nodejs_lambda(SLEEP_CODE), "envvar": nodejs_lambda(GET_ENV_VAR) } self.container_manager = ContainerManager() self.runtime = LambdaRuntime(self.container_manager)
def setUpClass(cls): cls.code_abs_path_for_throw_error = nodejs_lambda(THROW_ERROR_LAMBDA) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd_for_throw_error = os.path.dirname( cls.code_abs_path_for_throw_error) cls.code_uri_for_throw_error = os.path.relpath( cls.code_abs_path_for_throw_error, cls.cwd_for_throw_error) # Get relative path with respect to CWD cls.code_abs_path = nodejs_lambda(HELLO_FROM_LAMBDA) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd = os.path.dirname(cls.code_abs_path) cls.code_uri = os.path.relpath( cls.code_abs_path, cls.cwd) # Get relative path with respect to CWD cls.hello_world_function_name = "HelloWorld" cls.hello_world_function = provider.Function( name=cls.hello_world_function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri, environment=None, rolearn=None, layers=[]) cls.throw_error_function_name = "ThrowError" cls.throw_error_function = provider.Function( name=cls.throw_error_function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri_for_throw_error, environment=None, rolearn=None, layers=[]) cls.mock_function_provider = Mock() cls.mock_function_provider.get.side_effect = cls.mocked_function_provider cls.service, cls.port, cls.url, cls.scheme = make_service( cls.mock_function_provider, cls.cwd) cls.service.create() t = threading.Thread(name='thread', target=cls.service.run, args=()) t.setDaemon(True) t.start() time.sleep(1)
def setUp(self): self.code_dir = { "echo": nodejs_lambda(ECHO_CODE), "sleep": nodejs_lambda(SLEEP_CODE), "envvar": nodejs_lambda(GET_ENV_VAR) } self.container_manager = ContainerManager() layer_downloader = LayerDownloader("./", "./") self.lambda_image = LambdaImage(layer_downloader, False, False) self.runtime = LambdaRuntime(self.container_manager, self.lambda_image)
def setUpClass(cls): cls.code_abs_path = nodejs_lambda(ECHO_CODE) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd = os.path.dirname(cls.code_abs_path) cls.code_uri = os.path.relpath(cls.code_abs_path, cls.cwd) # Get relative path with respect to CWD cls.function_name = "HelloWorld" cls.function = provider.Function( name=cls.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri, environment=None, rolearn=None, layers=[], ) cls.mock_function_provider = Mock() cls.mock_function_provider.get.return_value = cls.function cls.service, cls.port, cls.url, cls.scheme = make_service(cls.mock_function_provider, cls.cwd) cls.service.create() # import pdb; pdb.set_trace() t = threading.Thread(name="thread", target=cls.service.run, args=()) t.setDaemon(True) t.start() time.sleep(1)
def setUp(self): self.code_abs_path = nodejs_lambda(GET_ENV_VAR) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder self.cwd = os.path.dirname(self.code_abs_path) self.code_uri = os.path.relpath( self.code_abs_path, self.cwd) # Get relative path with respect to CWD self.function_name = "name" self.variables = {"var1": "defaultvalue1", "var2": "defaultvalue2"} self.env_var_overrides = { self.function_name: { "var1": "override_value1" } } # Override "var2" through the Shell environment os.environ["var2"] = "shell_env_value2" self.function = provider.Function( name=self.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=self.code_uri, environment={"Variables": self.variables}, rolearn=None) self.mock_function_provider = Mock() self.mock_function_provider.get.return_value = self.function
def setUp(self): self.code_abs_path = nodejs_lambda(GET_ENV_VAR) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder self.cwd = os.path.dirname(self.code_abs_path) self.code_uri = os.path.relpath(self.code_abs_path, self.cwd) # Get relative path with respect to CWD self.function_name = "name" self.variables = { "var1": "defaultvalue1", "var2": "defaultvalue2" } self.env_var_overrides = { self.function_name: { "var1": "override_value1" } } # Override "var2" through the Shell environment os.environ["var2"] = "shell_env_value2" self.function = provider.Function(name=self.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=self.code_uri, environment={"Variables": self.variables}, rolearn=None, layers=[]) self.mock_function_provider = Mock() self.mock_function_provider.get.return_value = self.function
def setUp(self): self.host = "127.0.0.1" self.port = random.randint(30000, 40000) # get a random port self.url = "http://{}:{}".format(self.host, self.port) self.code_abs_path = nodejs_lambda(API_GATEWAY_ECHO_EVENT) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder self.cwd = os.path.dirname(self.code_abs_path) self.code_uri = os.path.relpath(self.code_abs_path, self.cwd) # Get relative path with respect to CWD # Setup a static file in the directory self.static_dir = "mystaticdir" self.static_file_name = "myfile.txt" self.static_file_content = "This is a static file" self._setup_static_file( os.path.join(self.cwd, self.static_dir), # Create static directory with in cwd self.static_file_name, self.static_file_content, ) # Create one Lambda function self.function_name = "name" self.function = provider.Function( name=self.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=self.code_uri, environment={}, rolearn=None, layers=[], ) self.mock_function_provider = Mock() self.mock_function_provider.get.return_value = self.function # Setup two APIs pointing to the same function routes = [ Route(path="/get", methods=["GET"], function_name=self.function_name), Route(path="/post", methods=["POST"], function_name=self.function_name), ] api = Api(routes=routes) self.api_provider_mock = Mock() self.api_provider_mock.get_all.return_value = api # Now wire up the Lambda invoker and pass it through the context self.lambda_invoke_context_mock = Mock() manager = ContainerManager() layer_downloader = LayerDownloader("./", "./") lambda_image = LambdaImage(layer_downloader, False, False) local_runtime = LambdaRuntime(manager, lambda_image) lambda_runner = LocalLambdaRunner(local_runtime, self.mock_function_provider, self.cwd, debug_context=None) self.lambda_invoke_context_mock.local_lambda_runner = lambda_runner self.lambda_invoke_context_mock.get_cwd.return_value = self.cwd
def setUp(self): random.seed() self.runtime = "nodejs4.3" self.expected_docker_image = self.IMAGE_NAME self.handler = "index.handler" self.debug_port = _rand_port() self.code_dir = nodejs_lambda(self.HELLO_WORLD_CODE) self.network_prefix = "sam_cli_test_network" self.docker_client = docker.from_env()
def setUp(self): random.seed() self.runtime = "nodejs4.3" self.expected_docker_image = self.IMAGE_NAME self.handler = "index.handler" self.layers = [] self.debug_port = _rand_port() self.debug_context = DebugContext(debug_port=self.debug_port, debugger_path=None, debug_args=None) self.code_dir = nodejs_lambda(self.HELLO_WORLD_CODE) self.network_prefix = "sam_cli_test_network" self.docker_client = docker.from_env()
def setUp(self): random.seed() self.runtime = "nodejs4.3" self.expected_docker_image = self.IMAGE_NAME self.handler = "index.handler" self.layers = [] self.debug_port = _rand_port() self.debug_context = DebugContext(debug_port=self.debug_port, debugger_path=None, debug_args=None) self.code_dir = nodejs_lambda(self.HELLO_WORLD_CODE) self.network_prefix = "sam_cli_test_network" self.docker_client = docker.from_env()
def setUp(self): self.host = "127.0.0.1" self.port = random.randint(30000, 40000) # get a random port self.url = "http://{}:{}".format(self.host, self.port) self.code_abs_path = nodejs_lambda(API_GATEWAY_ECHO_EVENT) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder self.cwd = os.path.dirname(self.code_abs_path) self.code_uri = os.path.relpath(self.code_abs_path, self.cwd) # Get relative path with respect to CWD # Setup a static file in the directory self.static_dir = "mystaticdir" self.static_file_name = "myfile.txt" self.static_file_content = "This is a static file" self._setup_static_file(os.path.join(self.cwd, self.static_dir), # Create static directory with in cwd self.static_file_name, self.static_file_content) # Create one Lambda function self.function_name = "name" self.function = provider.Function(name=self.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=self.code_uri, environment={}, rolearn=None, layers=[]) self.mock_function_provider = Mock() self.mock_function_provider.get.return_value = self.function # Setup two APIs pointing to the same function apis = [ provider.Api(path="/get", method="GET", function_name=self.function_name, cors="cors"), provider.Api(path="/post", method="POST", function_name=self.function_name, cors="cors"), ] self.api_provider_mock = Mock() self.api_provider_mock.get_all.return_value = apis # Now wire up the Lambda invoker and pass it through the context self.lambda_invoke_context_mock = Mock() manager = ContainerManager() layer_downloader = LayerDownloader("./", "./") lambda_image = LambdaImage(layer_downloader, False, False) local_runtime = LambdaRuntime(manager, lambda_image) lambda_runner = LocalLambdaRunner(local_runtime, self.mock_function_provider, self.cwd, env_vars_values=None, debug_context=None) self.lambda_invoke_context_mock.local_lambda_runner = lambda_runner self.lambda_invoke_context_mock.get_cwd.return_value = self.cwd
def setUp(self): self.code_dir = nodejs_lambda(SLEEP_CODE) Input = namedtuple('Input', ["timeout", "sleep", "check_stdout"]) self.inputs = [ Input(sleep=1, timeout=10, check_stdout=True), Input(sleep=2, timeout=10, check_stdout=True), Input(sleep=3, timeout=10, check_stdout=True), Input(sleep=5, timeout=10, check_stdout=True), Input(sleep=8, timeout=10, check_stdout=True), Input(sleep=13, timeout=12, check_stdout=False), # Must timeout Input(sleep=21, timeout=20, check_stdout=False), # Must timeout. So stdout will be empty ] random.shuffle(self.inputs) container_manager = ContainerManager() self.runtime = LambdaRuntime(container_manager)
def setUp(self): self.code_dir = nodejs_lambda(SLEEP_CODE) Input = namedtuple("Input", ["timeout", "sleep", "check_stdout"]) self.inputs = [ Input(sleep=1, timeout=10, check_stdout=True), Input(sleep=2, timeout=10, check_stdout=True), Input(sleep=3, timeout=10, check_stdout=True), Input(sleep=5, timeout=10, check_stdout=True), Input(sleep=8, timeout=10, check_stdout=True), Input(sleep=13, timeout=12, check_stdout=False), # Must timeout Input(sleep=21, timeout=20, check_stdout=False), # Must timeout. So stdout will be empty ] random.shuffle(self.inputs) container_manager = ContainerManager() layer_downloader = LayerDownloader("./", "./") self.lambda_image = LambdaImage(layer_downloader, False, False) self.runtime = LambdaRuntime(container_manager, self.lambda_image)
def setUpClass(cls): cls.code_abs_path = nodejs_lambda(ECHO_CODE) # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder cls.cwd = os.path.dirname(cls.code_abs_path) cls.code_uri = os.path.relpath(cls.code_abs_path, cls.cwd) # Get relative path with respect to CWD cls.function_name = "HelloWorld" cls.function = provider.Function(name=cls.function_name, runtime="nodejs4.3", memory=256, timeout=5, handler="index.handler", codeuri=cls.code_uri, environment=None, rolearn=None, layers=[]) cls.mock_function_provider = Mock() cls.mock_function_provider.get.return_value = cls.function cls.service, cls.port, cls.url, cls.scheme = make_service(cls.mock_function_provider, cls.cwd) cls.service.create() t = threading.Thread(name='thread', target=cls.service.run, args=()) t.setDaemon(True) t.start() time.sleep(1)