pip_services3_aws.services package

Submodules

Module contents

class pip_services3_aws.services.CommandableLambdaService(name: str)

Bases: pip_services3_aws.services.LambdaService.LambdaService, abc.ABC

Abstract service that receives commands via AWS Lambda protocol to operations automatically generated for commands defined in ICommandable components. Each command is exposed as invoke method that receives command name and parameters.

Commandable services require only 3 lines of code to implement a robust external Lambda-based remote interface.

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

Example:

class MyCommandableLambdaService(CommandableLambdaService):
    def __init__(self):
        super().__init__()
        self._dependency_resolver.put(
            "controller",
            Descriptor("mygroup","controller","*","*","1.0")
      )

service = MyCommandableLambdaService()
service.set_references(References.from_tuples(
    Descriptor("mygroup","controller","default","default","1.0"), controller
))

service.open("123")
print("The AWS Lambda service is running")
register()

Registers all actions in AWS Lambda function.

class pip_services3_aws.services.ILambdaService

Bases: abc.ABC

An interface that allows to integrate lambda services into lambda function containers and connect their actions to the function calls.

abstract get_actions() List[pip_services3_aws.services.LambdaAction.LambdaAction]

Get all actions supported by the service.

Returns

an array with supported actions.

class pip_services3_aws.services.LambdaAction(cmd: Optional[str] = None, schema: Optional[pip_services3_commons.validate.Schema.Schema] = None, action: Optional[Callable[[], Any]] = None)

Bases: object

action() Any

Action to be executed

class pip_services3_aws.services.LambdaService(name: Optional[str] = None)

Bases: pip_services3_aws.services.ILambdaService.ILambdaService, pip_services3_commons.run.IOpenable.IOpenable, pip_services3_commons.config.IConfigurable.IConfigurable, pip_services3_commons.refer.IReferenceable.IReferenceable, abc.ABC

Abstract service that receives remove calls via AWS Lambda protocol.

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

Example:

class MyLambdaService(LambdaService):
    _controller: IMyController
   ...

   def __init__(self):
        super().__init__('v1.myservice')
        self._dependency_resolver.put(
            "controller",
            Descriptor("mygroup","controller","*","*","1.0")
        )

   def set_references(self, references: IReferences):
      super().set_references(references)
      self._controller = self._dependency_resolver.get_required("controller")


   def __action(self, params):
        correlation_id = params.get('correlation_id')
        id = params.get('id')
        return self._controller.get_my_data(correlationId, id)

   def register(self):
       self.register_action("get_my_data", None, __action)

       ...


service = MyLambdaService()
service.configure(ConfigParams.from_tuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
))

service.set_references(References.from_tuples(
    Descriptor("mygroup","controller","default","default","1.0"), controller
))

service.open("123")
act(params: dict) Any

Calls registered action in this lambda function. “cmd” parameter in the action parameters determin what action shall be called.

This method shall only be used in testing.

Parameters

params – action parameters.

close(correlation_id: Optional[str])

Closes component and frees used resources.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

get_actions() List[pip_services3_aws.services.LambdaAction.LambdaAction]

Get all actions supported by the service.

Returns

an array with supported actions.

is_open() bool

Checks if the component is opened.

Returns

true if the component has been opened and false otherwise.

open(correlation_id: Optional[str])

Opens the component.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

abstract register()

Registers all service routes in HTTP endpoint.

This method is called by the service and must be overriden in child classes.

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to dependent components.

Parameters

references – references to locate the component dependencies.