Web

en_core.web

This module contains classes and functionality for web applications and services. Each of the sub-modules exposes functionality concrete to the application context (ie. Flask vs. Lambda), so that applications only need to import the functionality they need.

The library does not install any specific framework dependencies. It is the responsibility of the client application to manage those. For example, a Flask application will have to add Flask as a dependency and not assume this library will install it. This allows applications and services to specify the version of the dependency they need.

Serverless

en_core.web.serverless

Provides core functionality for AWS Serverless (AWS Lambda functions).

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 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.

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()