• Public
  • Public/Protected
  • All

Class LambdaFunction

Abstract AWS Lambda function, that acts as a container to instantiate and run components and expose them via external entry point.

When handling calls "cmd" parameter determines which what action shall be called, while other parameters are passed to the action itself.

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


  • *: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



class MyLambdaFunction extends LambdaFunction {
    private _controller: IMyController;
    public constructor() {
        base("mygroup", "MyGroup lambda function");
            new Descriptor("mygroup","controller","*","*","1.0")

    public setReferences(references: IReferences): void {
        this._controller = this._dependencyResolver.getRequired<IMyController>("controller");

    public register(): void {
        registerAction("get_mydata", null, (params, callback) => {
            let correlationId = params.correlation_id;
            let id = params.id;
            this._controller.getMyData(correlationId, id, callback);

let lambda = new MyLambdaFunction();

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





  • new LambdaFunction(name?: string, description?: string): LambdaFunction
  • Creates a new instance of this lambda function.


    • Optional name: string

      (optional) a container name (accessible via ContextInfo)

    • Optional description: string

      (optional) a container description (accessible via ContextInfo)

    Returns LambdaFunction


Protected _actions

_actions: object

The map of registered actions.

Type declaration

  • [id: string]: any

Protected _configPath

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

The default path to config file.

Protected _counters

_counters: any = new CompositeCounters()

The performanc counters.

Protected _dependencyResolver

_dependencyResolver: any = new DependencyResolver()

The dependency resolver.

Protected _schemas

_schemas: object

The map of registred validation schemas.

Type declaration

  • [id: string]: Schema



  • 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.


    • 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


  • 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.


    • 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.

Protected Abstract register

  • register(): void
  • Registers all actions in this lambda function.

    This method is called by the service and must be overriden in child classes.

    Returns void

Protected registerAction

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


    • 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(callback?: function): void
  • Runs this lambda function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.


    • Optional callback: function

      callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void


  • setReferences(references: IReferences): void
  • Sets references to dependent components.


    • references: IReferences

      references to locate the component dependencies.

    Returns void

Generated using TypeDoc