Extends: Container
Description
The LambdaFunction class allows you to create an abstract AWS Lambda function that acts as a container to instantiate and run components, and expose them via an external entry point.
Important points
-
When handling calls the “cmd” parameter determines what action shall be called, while the 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.
References
- *:logger:*:*:1.0: (optional) ILogger components to pass log messages.
- *:counters:*:*:1.0: (optional) ICounters components to pass collected measurements.
- *:service:lambda:*:1.0: (optional) ILambdaController services to handle action requests
- *:service:commandable-lambda:*:1.0: (optional) ILambdaController services to handle action requests
Constructors
Creates a new instance of this lambda function.
public
LambdaFunction(String name, String description)
- name: string - (optional) a container name (accessible via ContextInfo).
- description: string - (optional) container description (accessible via ContextInfo).
Fields
Instance methods
act
Calls registered action in this lambda function. The “cmd” parameter in the action parameters determines what action shall be called.
- This method shall only be used in testing.
public
Object act(Map<String, Object> params)
- params: Object - action parameters.
- returns: Object - result
execute
Executes this AWS Lambda function and returns the result. This method can be overloaded in child classes if it is necessary to change the default behavior
protected
Object execute(Map<String, Object> params) throws ApplicationException
- params: Object - event parameters (or function arguments)
- returns: Object - result of the function execution.
getHandler
Gets an entry point into this lambda function.
public
Function<Map<String, Object>, ?> getHandler()
- returns: Function<Map<String, Object>, ?> - incoming event object with invocation parameters.
instrument
Gets entry point into this lambda function.
protected
InstrumentTiming instrument(IContext context, String name)
- context: IContext - (optional) a context to trace execution through a call chain.
- name: String - method name.
- returns: InstrumentTiming - object to end the time measurement.
open
Opens the component.
public
void open(IContext) context) throws ApplicationException
- context: IContext - (optional) a context to trace execution through a call chain.
register
Registers all actions in this lambda function.
- Note: Overloading of this method has been deprecated. Use LambdaController instead.
protected
void register() throws ReferenceException
registerAction
Registers an action in this lambda function.
- Note: This method has been deprecated. Use LambdaController instead.
protected
void registerAction(String cmd, Schema schema, Function<Map<String, Object>, ?> action)
- cmd: String - action/command name.
- schema: Schema - validation schema used to validate received parameters.
- action: Function<Map<String, Object>, ?> - action function that is called when the action is invoked.
registerServices
Registers all lambda controllers in the container.
protected
void registerControllers() throws UnknownException
run
Runs this lambda function, loads container configuration, instantiates components and manages their lifecycle. Makes this function ready to access action calls.
public
void run() throws ApplicationExceptio
setReferences
Sets references to dependent components.
public
void setReferences(IReferences references) throws ReferenceException, ConfigException
- references: IReferences - references to locate the component’s dependencies.
Examples
class MyLambdaFunction extends LambdaFunction {
public MyLambdaFunction() {
super("mygroup", "MyGroup lambda function");
}
}
var lambda = new MyLambdaFunction();
lambda.run();