Implements: ILambdaController, IOpenable, IConfigurable, IReferenceable
Description
The LambdaController class allows you to create abstract services that receive remove calls via the AWS Lambda protocol.
Important points
This service is intended to work inside LambdaFunction container that exploses registered actions externally.
Configuration parameters
- dependencies:
- controller: override for Controller dependency
References
- *:logger:*:*:1.0: (optional) ILogger components to pass log messages.
- *:counters:*:*:1.0: (optional) ICounters components to pass collected measurements.
Constructors
Creates an instance of this service.
publicLambdaController(String name)
- name: string - service name to generate action cmd.
Fields
Instance methods
act
Calls registered action in this lambda function. The “cmd” parameter in the action parameters determines the action shall be called.
- This method shall only be used in testing.
publicObject act(Map<String, Object> params) throws ApplicationException
- params: Object - action parameters.
- returns: Object - results
applyInterceptors
Applies given action to the interseptors
protectedFunction<Map<String, Object>, ?> applyInterceptors(Function<Map<String, Object>, ?> action)
- action: Function<Map<String, Object>, ?> - applied action.
- returns: Function<Map<String, Object>, ?> - wrapped interceptors action.
applyValidation
Applies a validation according to a given schema.
protectedFunction<Map<String, Object>, ?> applyValidation(Schema schema, Function<Map<String, Object>, ?> action)
- schema: Schema - validation schema
- action: Function<Map<String, Object>, ?> - action
- returns: Function<Map<String, Object>, ?> - results
close
Closes a component and frees used resources.
publicvoid close(IContext context) throws ApplicationException
- context: IContext - (optional) a context to trace execution through a call chain.
configure
Configures a component by passing configuration parameters.
publicvoid configure(ConfigParams config) throws ConfigException
- config: ConfigParams - configuration parameters to be set.
generateActionCmd
Adds .cmd to the name of the command.
protectedString generateActionCmd(String name)
- name: string - name of the command
- returns: string - generated command
getActions
Gets all the actions supported by the service.
publicList<LambdaAction[]> getActions()
- returns: LambdaAction[] - array with supported actions.
instrument
Adds instrumentation to log calls and measures call time. It returns a Timing object that is used to end the time measurement.
protectedInstrumentTiming instrument(IContext context, String name)
- context: IContext - (optional) a context to trace execution through a call chain.
- name: string - method name.
- returns: InstrumentTiming - InstrumentTiming object to end the time measurement.
isOpen
Checks if the component is open.
publicboolean isOpen()
- returns: boolean - true if the component is open and false otherwise.
open
Opens the component.
publicvoid open(IContext context) throws ApplicationException
- context: IContext - (optional) a context to trace execution through a call chain.
registerAction
Registers an action in AWS Lambda function.
protectedvoid registerAction(String name, Schema schema, Function<Map<String, Object>, ?> action)
- name: string - action name
- schema: Schema - validation schema used to validate received parameters.
- action: Function<Map<String, Object>, ?> - action function that is called when an operation is invoked.
registerActionWithAuth
Registers an action with authorization.
protectedvoid registerActionWithAuth(String name, Schema schema, AuthorizeFunction<Map<String, Object>, Function<Map<String, Object>, ?>, ?> authorize, Function<Map<String, Object>, ?> action)
- name: string - action’s name
- schema: Schema - validation schema used to validate received parameters.
- authorize: Function<Map<String, Object>, ?>, ?> - authorization interceptor
- action: Function<Map<String, Object>, ?> - action function that is called when an operation is invoked.
registerInterceptor
Registers a middleware for actions in AWS Lambda service.
protectedvoid registerInterceptor(AuthorizeFunction<Map<String, Object>, Function<Map<String, Object>, ?>, ?> action)
- action: AuthorizeFunction<Map<String, Object>, Function<Map<String, Object>, ?>, ?> - action function that is called when middleware is invoked.
setReferences
Sets references to dependent components.
publicvoid setReferences(IReferences references) throws ReferenceException, ConfigException
- references: IReferences - references used to locate the component dependencies.
Abstract methods
register
Registers all service routes in an HTTP endpoint.
This method is called by the service and must be overriden in child classes.
protectedvoid register()
Examples
class MyLambdaController extends LambdaController {
private IMyService _service;
...
public MyLambdaController() {
super('v1.myservice');
this._dependencyResolver.put(
"service",
new Descriptor("mygroup","controller","*","*","1.0")
);
}
public void setReferences(references: ) {
super.setReferences(references);
this._service = this._dependencyResolver.getRequired(IDummyService.class, "service");
}
private MyData getData(IContext context, String id) {
return this._service.getMyData(context, id);
}
public void register() {
this.registerAction("/get_mydata",
null,
this::getData
);
...
}
}
var controller = new MyLambdaController();
controller.configure(ConfigParams.fromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 8080
));
controller.open("123");