Lambdas

Lambdas provide a way to run custom code in a remote edge environment. These lambdas can either be triggered manually, or they can be configured to be triggered by certain events which might include:

  • IoT Bus events such as GPIO edge triggers
  • Network events such as Kafka or Redis subscription events

When creating a new Lambda in the web console, a number of templates are offered:

Lambda Templates

Lambdas are written in Lua or JavaScript, and they can bundle WASM support libraries to support more complex operations such as evaluating Tensorflow or ONNX ML+AI models. This limited set of supported language runtimes ensures over-the-air deployability and sandbox security for edge logic, without the need for Docker or VMs, making the On Prem Agent suitable for use on resource-constrained operator-less edge devices.

The Lua or JavaScript code in a lambda will typically orchestrate native low-level modules that are either built into the agent (to support networking, local storage, and IoT busses), or that are provided by WASM modules built by you and deployed to the agent alongside the Lambda.

Running on a device

Lambdas are deployed as part of an agent's sealed configuration bundle, and are then able to run autonomously to perform workloads such as inference, ETL, or control functions, all without the need for cloud connectivity.

graph LR;

agent --> lambdas;
lambdas --> databases;
lambdas --> services;
lambdas --> busses;

subgraph device_edge[Device Edge]
agent;
databases[(Edge Databases)];
services[Network Services];
busses[IoT Busses];
end

subgraph agent[Agent]
lambdas[Lambdas];
end

Structure of a Lambda

Lua

Lambdas written in Lua are AWS Lambda compatible module tables that must include, at a minimum, a handler(event, context) function.

local inspect = require('inspect')
local M = {}

function M.handler(event, context)
  print('event has fired: %s', inspect(event))
  return {
    firstName = 'John',
    lastName = 'Doe',
    age = 23,
  }
end

return M

JavaScript

Lambdas written in JavaScript are AWS Lambda compatible JavaScript modules that must export a handler(event, context) function.

export const handler = async(event, context) => {
  console.log('event has fired:', event);
  return {
    firstName: 'John',
    lastName: 'Doe',
    age: 23,
  };
};

Lua Example

In this example, a Lambda is written to take a picture using a Raspberry Pi camera.

Lambda

While testing, Lambdas can be run manually via the CLI from a workstation at the developer edge.

$ onprem run lambda clv3b1c3v1vsk4qabftg --event-data-to-file out.jpeg
Wrote event[data] to out.jpeg (940.9K)

©2025 Megalithic LLC | Website | GitLab | GitLab (Megalithic)