Inherits: 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) ILambdaService services to handle action requests
- *:service:commandable-lambda:*:1.0: (optional) ILambdaService services to handle action requests
Constructors
Creates a new instance of this lambda function.
publicLambdaFunction(string name, string description)
- name: string - (optional) a container name (accessible via ContextInfo).
- description: string - (optional) container description (accessible via ContextInfo).
Fields
Instance methods
ActAsync
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.
publicTask<string> ActAsync(string input)
- input: string - action parameters.
- returns: Task<string> - result
ExecuteAsync
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
protectedTask<string> ExecuteAsync(string input)
- input: string - event parameters (or function arguments)
- returns: Task<string> - result of the function execution.
GetHandlerAsync
Gets an entry point into this lambda function.
publicFunc<string, Task<string>> GetHandlerAsync()
- returns: Func<string, Task<string>> - incoming event object with invocation parameters.
Instrument
Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.
protectedCounterTiming Instrument(string correlationId, string name)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- name: string - method name.
- returns: CounterTiming - CounterTiming object to end the time measurement.
InstrumentError
Adds instrumentation to error handling.
protectedvoid InstrumentError(string correlationId, string methodName, Exception ex, bool rethrow = false)
- correlationId: string - (optional) transaction id to trace execution through call chain.
- methodName: string - a method name.
- ex: Exception - Error that occured during the method call.
- rethrow: bool - True to throw the exception.
IsOpen
Checks if the component is open.
publicbool IsOpen()
- returns: bool - true if the component is open and false otherwise.
OpenAsync
Opens the component.
publicTask OpenAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
Register
Registers all actions in this lambda function.
- Note: Overloading of this method has been deprecated. Use LambdaService instead.
protectedvoid Register()
RegisterAction
Registers an action in this lambda function.
- Note: This method has been deprecated. Use LambdaService instead.
protectedvoid RegisterAction(string cmd, Schema schema, Func<string, Task<string>> action)
- cmd: string - action/command name.
- schema: Schema - validation schema used to validate received parameters.
- action: Func<string, Task<string>> - action function that is called when the action is invoked.
RegisterServices
Registers all lambda services in the container.
protectedvoid RegisterServices()
RunAsync
Runs this lambda function, loads container configuration, instantiates components and manages their lifecycle. Makes this function ready to access action calls.
publicasync Task RunAsync()
SetReferences
Sets references to dependent components.
publicvoid SetReferences(IReferences references)
- references: IReferences - references to locate the component’s dependencies.
Examples
class MyLambdaFunction extends LambdaFunction {
public MyLambdaFunction(): base("mygroup", "MyGroup lambda function") { }
}
var lambda = new MyLambdaFunction();
await service.RunAsync();
Console.WriteLine("MyLambdaFunction is started");