Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandableLambdaClient

Abstract client that calls commandable AWS Lambda Functions.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as action determined by "cmd" parameter.

Configuration parameters

  • 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
  • options:
    • connect_timeout: (optional) connection timeout in milliseconds (default: 10 sec)

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

LambdaFunction

Example

class MyLambdaClient extends CommandableLambdaClient implements IMyClient {
    ...

    public getData(correlationId: string, id: string,
        callback: (err: any, result: MyData) => void): void {

        this.callCommand(
            "get_data",
            correlationId,
            { id: id },
            (err, result) => {
                callback(err, result);
            }
        );
    }
    ...
}

let client = new MyLambdaClient();
client.configure(ConfigParams.fromTuples(
    "connection.region", "us-east-1",
    "connection.access_id", "XXXXXXXXXXX",
    "connection.access_key", "XXXXXXXXXXX",
    "connection.arn", "YYYYYYYYYYYYY"
));

client.getData("123", "1", (err, result) => {
    ...
});

Hierarchy

Implements

  • IOpenable
  • IConfigurable
  • IReferenceable

Index

Constructors

constructor

Properties

Protected _connection

_connection: AwsConnectionParams

The AWS connection parameters

Protected _connectionResolver

_connectionResolver: AwsConnectionResolver = new AwsConnectionResolver()

The connection resolver.

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performance counters.

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver()

The dependencies resolver.

Protected _lambda

_lambda: any

The reference to AWS Lambda Function.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _opened

_opened: boolean = false

The opened flag.

Methods

Protected call

  • call(cmd: string, correlationId: string, params?: any, callback?: function): void
  • Calls a AWS Lambda Function action.

    Parameters

    • cmd: string

      an action name to be called.

    • correlationId: string

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

    • Default value params: any = {}

      (optional) action parameters.

    • Optional callback: function

      (optional) callback function that receives result object or error.

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

          • err: any
          • result: any

          Returns void

    Returns void

callCommand

  • callCommand(cmd: string, correlationId: string, params: any, callback: function): void
  • Calls a remote action in AWS Lambda function. The name of the action is added as "cmd" parameter to the action parameters.

    Parameters

    • cmd: string

      an action name

    • correlationId: string

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

    • params: any

      command parameters.

    • callback: function

      callback function that receives result or error.

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

          • err: any
          • result: any

          Returns void

    Returns void

Protected callOneWay

  • callOneWay(cmd: string, correlationId: string, params?: any, callback?: function): void
  • Calls a AWS Lambda Function action asynchronously without waiting for response.

    Parameters

    • cmd: string

      an action name to be called.

    • correlationId: string

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

    • Default value params: any = {}

      (optional) action parameters.

    • Optional callback: function

      (optional) callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): 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.

Protected invoke

  • invoke(invocationType: string, cmd: string, correlationId: string, args: any, callback?: function): void
  • Performs AWS Lambda Function invocation.

    Parameters

    • invocationType: string

      an invocation type: "RequestResponse" or "Event"

    • cmd: string

      an action name to be called.

    • correlationId: string

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

    • args: any

      action arguments

    • Optional callback: function

      callback function that receives action result or error.

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

          • err: any
          • result: any

          Returns void

    Returns void

isOpen

  • isOpen(): boolean

open

  • open(correlationId: string, callback: function): void
  • Opens the component.

    Parameters

    • correlationId: string

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

    • callback: function

      callback function that receives error or null no errors occured.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void

Generated using TypeDoc