LambdaClient

Abstract client that calls AWS Lambda Functions.

Implements: IOpenable, IConfigurable, IReferenceable

Description

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

Configuration parameters

  • connections:
    • discovery_key: (optional) key to retrieve the connection from IDiscovery
    • region: (optional) AWS region
  • credentials:
    • store_key: (optional) key to retrieve the credentials from ICredentialStore
    • access_id: AWS access/client id
    • access_key: AWS access/client key
  • 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 connections.
  • *:credential-store:*:*:1.0 - (optional) Credential stores to resolve credentials.

Fields

connection

AWS connection parameters

connection: AwsConnectionParams

_connectionResolver

The connection resolver.

connectionResolver: AwsConnectionResolver

counters

Performance counters.

counters: CompositeCounters

dependencyResolver

Dependencies resolver.

dependencyResolver: DependencyResolver

lambda

Reference to AWS Lambda Function.

lambda: Lambda

logger

Logger.

logger: CompositeLogger

opened

Opened flag.

opened: bool

Instance methods

call

Calls an AWS Lambda Function action.

Future call(String cmd, IContext context, params)

  • cmd: String - action name to be called.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • params: dynamic - (optional) action parameters.
  • returns: Future - action result.

callOneWay

Calls a AWS Lambda Function action asynchronously without waiting for response.

Future callOneWay(String cmd, IContext context, params)

  • cmd: String - an action name to be called.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • params: dynamic - (optional) action parameters.
  • returns: Future - action result.

close

Closes component and frees used resources.

@override

Future close(IContext context)

  • context: IContext - (optional) a context to trace execution through a call chain.

configure

Configures a component by passing its configuration parameters.

@override

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

instrument

Adds instrumentation to log calls and measures call time. It returns a InstrumentTiming object that is used to end the time measurement.

CounterTiming instrument(IContext context, String name)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • name: String - a method name.
  • returns: CounterTiming - object to end the time measurement.

invoke

Performs AWS Lambda Function invocation.

Future invoke(LambdaInvocationType invocationType, String cmd, IContext context, Map args)

  • invocationType: String - invocation type: “RequestResponse” or “Event”
  • cmd: String - action name to be called.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • args: Map - action arguments
  • returns: Future - action result.

isOpen

Checks if the component is open.

@override

bool isOpen()

  • returns: bool - true if the component is open and false otherwise.

open

Opens the component.

@override

Future open(IContext context)

  • context: IContext - (optional) a context to trace execution through a call chain.

setReferences

Sets references to dependent components.

@override

void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

Examples

class MyLambdaClient extends LambdaClient implements IMyClient {
    ...
    public getData(IContext context, id: string,
        callback: (err: any, result: MyData) => void): void {
        var counter_timing = this.instrument(context, 'myclient.get_data');
        this.call('get_data' context, { id: id }, (err, result) => {
            counter_timing.endTiming();
            callback(err, result);
        });
    }
    ...
}

var 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) => {
    ...
});

See also