Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandableLambdaFunction

Abstract AWS Lambda function, that acts as a container to instantiate and run components and expose them via external entry point. All actions are automatically generated for commands defined in ICommandable components. Each command is exposed as an action defined by "cmd" parameter.

Container configuration for this Lambda function is stored in "./config/config.yml" file. But this path can be overriden by CONFIG_PATH environment variable.

Configuration parameters

  • dependencies:
    • controller: override for Controller dependency
  • connections:
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • region: (optional) AWS region
  • credentials:
    • store_key: (optional) a key to retrieve the credentials from ICredentialStore
    • access_id: AWS access/client id
    • access_key: AWS access/client id

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
see

LambdaClient

Example

class MyLambdaFunction extends CommandableLambdaFunction {
    private _controller: IMyController;
    ...
    public constructor() {
        base("mygroup", "MyGroup lambda function");
        this._dependencyResolver.put(
            "controller",
            new Descriptor("mygroup","controller","*","*","1.0")
        );
    }
}

let lambda = new MyLambdaFunction();

service.run((err) => {
    console.log("MyLambdaFunction is started");
});

Hierarchy

Implements

  • IConfigurable
  • IReferenceable
  • IUnreferenceable
  • IOpenable

Index

Constructors

constructor

Properties

Protected _actions

_actions: object

The map of registered actions.

Type declaration

  • [id: string]: any

Protected _config

_config: ContainerConfig

Protected _configPath

_configPath: string = "./config/config.yml"

The default path to config file.

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performanc counters.

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver()

The dependency resolver.

Protected _factories

_factories: DefaultContainerFactory

Protected _info

_info: ContextInfo

Protected _logger

_logger: ILogger

Protected _references

_references: ContainerReferences

Protected _schemas

_schemas: object

The map of registred validation schemas.

Type declaration

  • [id: string]: Schema

Methods

act

  • act(params: any, callback: function): void
  • Calls registered action in this lambda function. "cmd" parameter in the action parameters determin what action shall be called.

    This method shall only be used in testing.

    Parameters

    • params: any

      action parameters.

    • callback: function

      callback function that receives action result or error.

        • (err: any, result: any): void
        • Parameters

          • err: any
          • result: any

          Returns void

    Returns void

addFactory

  • addFactory(factory: IFactory): void
  • Adds a factory to the container. The factory is used to create components added to the container by their locators (descriptors).

    Parameters

    • factory: IFactory

      a component factory to be added.

    Returns void

close

  • close(correlationId: string, callback?: function): void
  • Stops the container by unsetting references for child containers and closing (+ dereferencing) the container's components.

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • Optional callback: function

      (optional) the function to call when the closing process is complete. It will be called with an error if one is raised.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Creates a [[ContainerConfig]] from the passed ConfigParams, which is used to configure the components of this container.

    see

    [[ContainerConfig.fromConfig]]

    see

    ConfigParams (in the PipServices "Commons" package)

    Parameters

    • config: ConfigParams

      the ConfigParams to configure the container with.

    Returns void

getHandler

  • getHandler(): function
  • Gets entry point into this lambda function.

    Returns function

      • (event: any, context: any): void
      • Parameters

        • event: any

          an incoming event object with invocation parameters.

        • context: any

          a context object with local references.

        Returns void

Protected instrument

  • instrument(correlationId: string, name: string): Timing
  • Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • name: string

      a method name.

    Returns Timing

    Timing object to end the time measurement.

isOpen

  • isOpen(): boolean
  • Returns boolean

    whether or not any references have been set in this container.

open

  • open(correlationId: string, callback?: function): void
  • Starts the container by setting references to components (in accordance with the container's configuration), setting child containers' references, and opening all referenced components.

    If a custom "context-info" Descriptor is present in the set references, it will also be set.

    throws

    an InvalidStateException if the container has already been opened (references are set).

    see

    ContextInfo (in the PipServices "Components" package)

    see

    Descriptor (in the PipServices "Commons" package)

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • Optional callback: function

      (optional) the function to call when the opening process is complete. It will be called with an error if one is raised. If omitted, errors will be thrown by this method.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

readConfigFromFile

  • readConfigFromFile(correlationId: string, path: string, parameters: ConfigParams): void
  • Reads JSON/YAML data from the target file to this container's [[ContainerConfig]].

    see

    [[ContainerConfigReader.readFromFile]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • path: string

      the path to the target file, containing configuration parameters. Must not be null.

    • parameters: ConfigParams

      used to parameterize the ConfigReader.

    Returns void

register

  • register(): void

Protected registerAction

  • registerAction(cmd: string, schema: Schema, action: function): void
  • Registers an action in this lambda function.

    Parameters

    • cmd: string

      a action/command name.

    • schema: Schema

      a validation schema to validate received parameters.

    • action: function

      an action function that is called when action is invoked.

        • (params: any, callback: function): void
        • Parameters

          • params: any
          • callback: function
              • (err: any, result: any): void
              • Parameters

                • err: any
                • result: any

                Returns void

          Returns void

    Returns void

run

  • run(callback?: function): void
  • Runs this lambda function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.

    Parameters

    • Optional callback: function

      callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void

unsetReferences

  • unsetReferences(): void
  • Method that should be overriden in child classes (child containers). Should unset the child containers' component references.

    Returns void

Generated using TypeDoc