Lambda Modules

omega|ml supports execution of arbitrary modules packaged by pip on the runtime cluster. This is the equivalent of AWS Lambda with the added bonus of having the full set of omega|ml capabilities available to your modules.

Writing a Lambda Module

Creating a Lambda Module is straight forward:

  1. write your code

  2. add setup.py

  3. use om.scripts.put() to deploy the package

To make your code executable through the REST API or in om.runtime.script your code’s top-level package must contain a run() method:

def run(*args, **kwargs):
     ...

kwargs will contain the key/value pair passed to the module on execution.

The simplest setup.py is as simple as follows (:

from distutils.core import setup
setup(name='helloworld', version='1.0',
      description='simple omegaml hello world script', author='omegaml',
      author_email='info@omegaml.io', url='http://omegaml.io',
      packages=['helloworld'],)

Deploying a module

To deploy a Lambda module use om.scripts.put():

om.scripts.put('pkg://path/to/helloworld`, 'helloworld')

This will build the package and store it in omega|ml. It is automatically available for execution using the REST API or om.runtime.script().

Executing a module

Using the REST API

Use the /api/script/ REST API to execute a module:

POST /api/script/hellworld/?param=value
=>
{
    'script': 'helloworld'
    'kwargs': { 'param': value },
    'result': <result>,
    'runtime': <microseconds>,
    'started': 'datetime in iso 8601 format',
}

Using the runtime API

Use the om.runtime.script(<name>) API to run a module on the cluster:

result = om.runtime.script('helloworld').run(foo='bar')
result.get()
=>
{
    'script': 'helloworld'
    'kwargs': { 'foo': 'bar' },
    'result': <result>,
    'runtime': <microseconds>,
    'started': 'datetime in iso 8601 format',
}