Documentation ¶
Index ¶
- type CommandableLambdaFunction
- type ILambdaFunctionOverrides
- type LambdaFunction
- func (c *LambdaFunction) Act(params map[string]interface{}) (string, error)
- func (c *LambdaFunction) GetHandler() func(ctx context.Context, event map[string]interface{}) (string, error)
- func (c *LambdaFunction) Handler(ctx context.Context, event map[string]interface{}) (string, error)
- func (c *LambdaFunction) Instrument(correlationId string, name string) *rpcserv.InstrumentTiming
- func (c *LambdaFunction) InstrumentError(correlationId string, name string, errIn error, resIn interface{}) (result interface{}, err error)
- func (c *LambdaFunction) Open(correlationId string) error
- func (c *LambdaFunction) RegisterAction(cmd string, schema *cvalid.Schema, ...) error
- func (c *LambdaFunction) RegisterServices()
- func (c *LambdaFunction) Run() error
- func (c *LambdaFunction) SetReferences(references cref.IReferences)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandableLambdaFunction ¶
type CommandableLambdaFunction struct {
*LambdaFunction
}
Abstract AWS Lambda function, that acts as a container to instantiate and run components and expose them via external entry point. All actions are automatically generated for commands defined in ICommandable components. Each command is exposed as an action defined by "cmd" parameter.
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
### 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 LambdaClient
### Example ### class MyLambdaFunction extends CommandableLambdaFunction { private _controller: IMyController; ... func (c* CommandableLambdaFunction) constructor() { base("mygroup", "MyGroup lambda function"); c.dependencyResolver.put( "controller", new Descriptor("mygroup","controller","*","*","1.0") ); } } let lambda = new MyLambdaFunction(); service.run((err) => { console.log("MyLambdaFunction is started"); });
func NewCommandableLambdaFunction ¶
func NewCommandableLambdaFunction(name string, description string) *CommandableLambdaFunction
Creates a new instance of this lambda function.
- name (optional) a container name (accessible via ContextInfo)
- description (optional) a container description (accessible via ContextInfo)
func (*CommandableLambdaFunction) Register ¶
func (c *CommandableLambdaFunction) Register()
Registers all actions in this lambda function.
type ILambdaFunctionOverrides ¶
type ILambdaFunctionOverrides interface { cref.IReferenceable // Perform required registration steps. Register() }
type LambdaFunction ¶
type LambdaFunction struct { *cproc.Container Overrides ILambdaFunctionOverrides // The dependency resolver. DependencyResolver *cref.DependencyResolver // contains filtered or unexported fields }
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
### 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 LambdaClient
### Example ### class MyLambdaFunction extends LambdaFunction { func (c* LambdaFunction) _controller: IMyController; ... func (c* LambdaFunction) constructor() { base("mygroup", "MyGroup lambda function"); c.dependencyResolver.put( "controller", new Descriptor("mygroup","controller","*","*","1.0") ); } func (c* LambdaFunction) setReferences(references: IReferences){ base.setReferences(references); c.controller = c.dependencyResolver.getRequired<IMyController>("controller"); } func (c* LambdaFunction) register(){ registerAction("get_mydata", null, (params, callback) => { let correlationId = params.correlation_id; let id = params.id; c.controller.getMyData(correlationId, id, callback); }); ... } } let lambda = new MyLambdaFunction(); service.run((err) => { console.log("MyLambdaFunction is started"); });
func InheriteLambdaFunction ¶
func InheriteLambdaFunction(overrides ILambdaFunctionOverrides, name string, description string) *LambdaFunction
Creates a new instance of this lambda function.
- name (optional) a container name (accessible via ContextInfo)
- description (optional) a container description (accessible via ContextInfo)
func (*LambdaFunction) Act ¶
func (c *LambdaFunction) Act(params map[string]interface{}) (string, error)
func (*LambdaFunction) GetHandler ¶
func (*LambdaFunction) Instrument ¶
func (c *LambdaFunction) Instrument(correlationId string, name string) *rpcserv.InstrumentTiming
Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.
- correlationId (optional) transaction id to trace execution through call chain.
- name a method name.
Returns Timing object to end the time measurement.
func (*LambdaFunction) InstrumentError ¶
func (c *LambdaFunction) InstrumentError(correlationId string, name string, errIn error, resIn interface{}) (result interface{}, err error)
InstrumentError method are adds instrumentation to error handling. Parameters:
- correlationId string (optional) transaction id to trace execution through call chain.
- name string a method name.
- err error an occured error
- result interface{} (optional) an execution result
Returns: result interface{}, err error (optional) an execution callback
func (*LambdaFunction) Open ¶
func (c *LambdaFunction) Open(correlationId string) error
Opens the component. - correlationId (optional) transaction id to trace execution through call chain.
func (*LambdaFunction) RegisterAction ¶
func (c *LambdaFunction) RegisterAction(cmd string, schema *cvalid.Schema, action func(params map[string]interface{}) (result interface{}, err error)) error
Registers an action in this lambda function.
- cmd a action/command name.
- schema a validation schema to validate received parameters.
- action an action function that is called when action is invoked.
func (*LambdaFunction) RegisterServices ¶
func (c *LambdaFunction) RegisterServices()
Registers all lambda services in the container.
func (*LambdaFunction) Run ¶
func (c *LambdaFunction) Run() error
Runs this lambda function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.
- callback callback function that receives error or null for success.
func (*LambdaFunction) SetReferences ¶
func (c *LambdaFunction) SetReferences(references cref.IReferences)
Sets references to dependent components.
- references references to locate the component dependencies.