Reference Guide

en_serverless

This module provides core functionality to invoke and handle calls to AWS Lambda. The module can be used by Envase applications and services with access to AWS Lambda to invoke functions and retrieve the results.

The module also provides functionality to call the same AWS Lambda functions in a local environment during testing. The interfaces are exactly the same to insure that the client code is correct while running locally in a development environment or when running in the cloud or production system.

exception InvalidFunctionTypeError(specified_function)

Raised when the specified local function is not a callable.

exception LambdaClientError(func, client_error)

Indicates the Lambda client has returned an error. Usually, because the lambda function was not found.

exception LambdaExecuteError(func, error_payload)

Indicates an error executing a Lambda fucntion.

class LambdaFunctionDispatcher(lambda_client=None)

Implements dispatcher interface to invoke Lambda functions hosted in AWS. The lambda_client parameter is used for testing purposes and should not be specified in most production code.

dispatch(func, event=None)

Dispatches the specified function with the specified event parameters. This function waits for a result of the function and returns it.

Parameters:
  • func (str) – Name of the function to dispatch.

  • event (dict) – Optional parameters to use to invoke the function

dispatch_async(func, event=None)

Dispatches the specified function with the specified event parameters asynchronously. This method does not wait for the function to finish execution, so the return value will be the result from AWS.

Parameters:
  • func (str) – Name of the function to dispatch.

  • event (dict) – Optional parameters to use to invoke the function

class LocalFunctionDispatcher

Implements the dispatcher interface to invoke a local function that acts as a Lambda function handler.

dispatch(func, event=None)

Dispatches the specified function with the specified event parameters and returns the result.

Parameters:
  • func (callable) – Callable object, usually a Lambda function entry point, to be invoked.

  • event (dict) – Parameters to pass to the Lambda function.

dispatch_async(func, event=None)

With local functions, this method is synonym of dispatch()

Base Lambda handlers

en_serverless.handlers

This module provides base classes to implement AWS Lambda function handlers. These handlers become the entry point to the work done by the AWS Lambda function.

Application functionality is provided by an IExecutionContext interface that is application specific; therefore, client applications can customize how the AWS Lambda event and context are provided, as well as the configuration and notification service for messaging.

class LambdaHandler(execution_context)

Base class for all lambda function handlers. Applications and services should derive from this class to insure appropriate initialization of the execution context and to provide the interface to execute the process.

Parameters:

execution_context (ExecutionContext) – Object representing the execution context. This object should provide access to the lambda event, the lambda context object, and the configuration used during the execution. The object should also provide a .notify(error) method that takes an exception object and notifies the notification service.

property config

Returns the configuration object where configuration parameters are stored. The configuration object returned by the execution context should support the .get(key, _default=None) interface.

property context

Returns the context object provided by AWS.

property event

Returns the lambda event provided during execution. The execution context should return an object (not the payload) containing the parameters passed to the lambda function.

notify(error)

Notifies about an error using the execution context.

Parameters:

error (Exception) – Exception that caused the notification.