Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lambdas

Lambdas provide a way to run custom code that reacts to certain events. These might include:

  • IoT Bus events such as GPIO edge triggers
  • network events like Kafka or Redis subscriptions

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

Lambda Templates

Lambdas are written in Lua for over-the-air deployability. That Lua will typically orchestrate native low-level modules that are either built into the agent (to support networking, storage, and IoT busses), or provided by WASM modules provided by you.

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 ETL or control functions 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

Lambdas are AWS Lambda compatible Lua module tables that at a minimum must include a handler() function.

local M = {}

function M.handler(event, context)
  print('event has fired')
  return {
    -- SampleKey = 'sample value'
  }
end

return M

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)