コード例 #1
0
ファイル: cli.py プロジェクト: zhangyi733/aws-sam-cli
def do_cli(ctx, host, port, template, env_vars, debug_port, debug_args,  # pylint: disable=R0914
           docker_volume_basedir, docker_network, log_file, skip_pull_image, profile):
    """
    Implementation of the ``cli`` method, just separated out for unit testing purposes
    """

    LOG.debug("local start_lambda command is called")

    # Pass all inputs to setup necessary context to invoke function locally.
    # Handler exception raised by the processor for invalid args and print errors

    try:
        with InvokeContext(template_file=template,
                           function_identifier=None,  # Don't scope to one particular function
                           env_vars_file=env_vars,
                           debug_port=debug_port,
                           debug_args=debug_args,
                           docker_volume_basedir=docker_volume_basedir,
                           docker_network=docker_network,
                           log_file=log_file,
                           skip_pull_image=skip_pull_image,
                           aws_profile=profile) as invoke_context:

            service = LocalLambdaService(lambda_invoke_context=invoke_context,
                                         port=port,
                                         host=host)
            service.start()

    except InvalidSamDocumentException as ex:
        raise UserException(str(ex))
コード例 #2
0
    def test_start(self, local_lambda_invoke_service_mock):
        lambda_runner_mock = Mock()
        stderr_mock = Mock()
        lambda_invoke_context_mock = Mock()

        lambda_context_mock = Mock()
        local_lambda_invoke_service_mock.return_value = lambda_context_mock

        lambda_invoke_context_mock.local_lambda_runner = lambda_runner_mock
        lambda_invoke_context_mock.stderr = stderr_mock

        service = LocalLambdaService(
            lambda_invoke_context=lambda_invoke_context_mock,
            port=3000,
            host="localhost")

        service.start()

        local_lambda_invoke_service_mock.assert_called_once_with(
            lambda_runner=lambda_runner_mock,
            port=3000,
            host="localhost",
            stderr=stderr_mock)
        lambda_context_mock.create.assert_called_once()
        lambda_context_mock.run.assert_called_once()
コード例 #3
0
def do_cli(  # pylint: disable=R0914
    ctx,
    host,
    port,
    template,
    env_vars,
    debug_port,
    debug_args,
    debugger_path,
    docker_volume_basedir,
    docker_network,
    log_file,
    layer_cache_basedir,
    skip_pull_image,
    force_image_build,
    parameter_overrides,
):
    """
    Implementation of the ``cli`` method, just separated out for unit testing purposes
    """

    LOG.debug("local start_lambda command is called")

    # Pass all inputs to setup necessary context to invoke function locally.
    # Handler exception raised by the processor for invalid args and print errors

    try:
        with InvokeContext(
                template_file=template,
                function_identifier=
                None,  # Don't scope to one particular function
                env_vars_file=env_vars,
                docker_volume_basedir=docker_volume_basedir,
                docker_network=docker_network,
                log_file=log_file,
                skip_pull_image=skip_pull_image,
                debug_port=debug_port,
                debug_args=debug_args,
                debugger_path=debugger_path,
                parameter_overrides=parameter_overrides,
                layer_cache_basedir=layer_cache_basedir,
                force_image_build=force_image_build,
                aws_region=ctx.region,
                aws_profile=ctx.profile,
        ) as invoke_context:

            service = LocalLambdaService(lambda_invoke_context=invoke_context,
                                         port=port,
                                         host=host)
            service.start()

    except (
            InvalidSamDocumentException,
            OverridesNotWellDefinedError,
            InvalidLayerReference,
            DebuggingNotSupported,
    ) as ex:
        raise UserException(str(ex))
コード例 #4
0
    def test_start(self, local_lambda_invoke_service_mock):
        lambda_runner_mock = Mock()
        stderr_mock = Mock()
        lambda_invoke_context_mock = Mock()

        lambda_context_mock = Mock()
        local_lambda_invoke_service_mock.return_value = lambda_context_mock

        lambda_invoke_context_mock.local_lambda_runner = lambda_runner_mock
        lambda_invoke_context_mock.stderr = stderr_mock

        service = LocalLambdaService(lambda_invoke_context=lambda_invoke_context_mock, port=3000, host='localhost')

        service.start()

        local_lambda_invoke_service_mock.assert_called_once_with(lambda_runner=lambda_runner_mock,
                                                                 port=3000,
                                                                 host='localhost',
                                                                 stderr=stderr_mock)
        lambda_context_mock.create.assert_called_once()
        lambda_context_mock.run.assert_called_once()
コード例 #5
0
ファイル: cli.py プロジェクト: Frameio/aws-sam-cli
def do_cli(ctx, host, port, template, env_vars, debug_port, debug_args,  # pylint: disable=R0914
           debugger_path, docker_volume_basedir, docker_network, log_file, layer_cache_basedir, skip_pull_image,
           force_image_build, parameter_overrides):
    """
    Implementation of the ``cli`` method, just separated out for unit testing purposes
    """

    LOG.debug("local start_lambda command is called")

    # Pass all inputs to setup necessary context to invoke function locally.
    # Handler exception raised by the processor for invalid args and print errors

    try:
        with InvokeContext(template_file=template,
                           function_identifier=None,  # Don't scope to one particular function
                           env_vars_file=env_vars,
                           docker_volume_basedir=docker_volume_basedir,
                           docker_network=docker_network,
                           log_file=log_file,
                           skip_pull_image=skip_pull_image,
                           debug_port=debug_port,
                           debug_args=debug_args,
                           debugger_path=debugger_path,
                           parameter_overrides=parameter_overrides,
                           layer_cache_basedir=layer_cache_basedir,
                           force_image_build=force_image_build,
                           aws_region=ctx.region) as invoke_context:

            service = LocalLambdaService(lambda_invoke_context=invoke_context,
                                         port=port,
                                         host=host)
            service.start()

    except (InvalidSamDocumentException,
            OverridesNotWellDefinedError,
            InvalidLayerReference,
            DebuggingNotSupported) as ex:
        raise UserException(str(ex))
コード例 #6
0
    def test_initialization(self):
        lambda_runner_mock = Mock()
        stderr_mock = Mock()
        lambda_invoke_context_mock = Mock()

        lambda_invoke_context_mock.local_lambda_runner = lambda_runner_mock
        lambda_invoke_context_mock.stderr = stderr_mock

        service = LocalLambdaService(lambda_invoke_context=lambda_invoke_context_mock, port=3000, host='localhost')

        self.assertEquals(service.port, 3000)
        self.assertEquals(service.host, 'localhost')
        self.assertEquals(service.lambda_runner, lambda_runner_mock)
        self.assertEquals(service.stderr_stream, stderr_mock)
コード例 #7
0
ファイル: cli.py プロジェクト: uu64/aws-sam-cli
def do_cli(  # pylint: disable=R0914
    ctx,
    host,
    port,
    template,
    env_vars,
    debug_port,
    debug_args,
    debugger_path,
    container_env_vars,
    docker_volume_basedir,
    docker_network,
    log_file,
    layer_cache_basedir,
    skip_pull_image,
    force_image_build,
    parameter_overrides,
    warm_containers,
    shutdown,
    debug_function,
    container_host,
    container_host_interface,
):
    """
    Implementation of the ``cli`` method, just separated out for unit testing purposes
    """

    from samcli.commands.local.cli_common.invoke_context import InvokeContext
    from samcli.commands.local.cli_common.user_exceptions import UserException
    from samcli.lib.providers.exceptions import InvalidLayerReference
    from samcli.commands.local.lib.local_lambda_service import LocalLambdaService
    from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException
    from samcli.commands.local.lib.exceptions import OverridesNotWellDefinedError
    from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported

    LOG.debug("local start_lambda command is called")

    # Pass all inputs to setup necessary context to invoke function locally.
    # Handler exception raised by the processor for invalid args and print errors

    try:
        with InvokeContext(
                template_file=template,
                function_identifier=
                None,  # Don't scope to one particular function
                env_vars_file=env_vars,
                docker_volume_basedir=docker_volume_basedir,
                docker_network=docker_network,
                log_file=log_file,
                skip_pull_image=skip_pull_image,
                debug_ports=debug_port,
                debug_args=debug_args,
                debugger_path=debugger_path,
                container_env_vars_file=container_env_vars,
                parameter_overrides=parameter_overrides,
                layer_cache_basedir=layer_cache_basedir,
                force_image_build=force_image_build,
                aws_region=ctx.region,
                aws_profile=ctx.profile,
                warm_container_initialization_mode=warm_containers,
                debug_function=debug_function,
                shutdown=shutdown,
                container_host=container_host,
                container_host_interface=container_host_interface,
        ) as invoke_context:

            service = LocalLambdaService(lambda_invoke_context=invoke_context,
                                         port=port,
                                         host=host)
            service.start()

    except (
            InvalidSamDocumentException,
            OverridesNotWellDefinedError,
            InvalidLayerReference,
            InvalidIntermediateImageError,
            DebuggingNotSupported,
    ) as ex:
        raise UserException(str(ex),
                            wrapped_from=ex.__class__.__name__) from ex
    except ContainerNotStartableException as ex:
        raise UserException(str(ex),
                            wrapped_from=ex.__class__.__name__) from ex