Exemple #1
0
def do_cli(
        ctx,
        host,
        port,
        static_dir,
        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-api 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 = LocalApiService(lambda_invoke_context=invoke_context,
                                      port=port,
                                      host=host,
                                      static_dir=static_dir)
            service.start()

    except NoApisDefined:
        raise UserException(
            "Template does not have any APIs connected to Lambda functions")
    except InvalidSamDocumentException as ex:
        raise UserException(str(ex))
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))
Exemple #3
0
def do_cli(ctx, function_identifier, template, event, env_vars, debug_port,
           debug_args, 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 invoke command is called")

    event_data = _get_event(event)

    # 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=function_identifier,
                           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 context:

            # Invoke the function
            context.local_lambda_runner.invoke(context.function_name,
                                               event=event_data,
                                               stdout=context.stdout,
                                               stderr=context.stderr)

    except FunctionNotFound:
        raise UserException(
            "Function {} not found in template".format(function_identifier))
    except InvalidSamDocumentException as ex:
        raise UserException(str(ex))
Exemple #4
0
def do_cli(ctx, location, runtime, output_dir, name, no_input):
    """
    Implementation of the ``cli`` method, just separated out for unit testing purposes
    """
    LOG.debug("Init command")
    click.secho("[+] Initializing project structure...", fg="green")

    try:
        generate_project(location, runtime, output_dir, name, no_input)
        # Custom templates can implement their own visual cues so let's not repeat the message
        if not location:
            click.secho(
                "[SUCCESS] - Read {name}/README.md for further instructions on how to proceed"
                .format(name=name),
                bold=True)
        click.secho("[*] Project initialization is now complete", fg="green")
    except GenerateProjectFailedError as e:
        raise UserException(str(e))
Exemple #5
0
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