Lambdas
Lambdas provide a way to run custom code that reacts to certain events. These might include:
- network events like Kafka or Redis subscriptions
- IoT Bus events such as GPIO edge triggers
- platform events such as the preparation of a configuration bundle during device reconfiguration
When creating a new Lambda in the web console, number of templates are offered:
Lambdas are written in Lua for over-the-air deployability. That Lua will typically orchestrate native low-level modules that are built into the agent to support networking, storage, and IoT busses.
Running on a device
Most Lambdas will run within an agent at the device edge, where they are deployed as part of the 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 reliable 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
Running at the control plane
Additionally, some Lambdas can run within an embedded Lua VM at the control plane. These types of Lambdas typically run during preparation of device configuration bundles, and they include hardware driver Lambdas for various blades, chasses, and HATs.
graph LR; lambdas --> databases; lambdas --> services; subgraph cloud[Cloud] control_plane; databases[(Cloud Databases)]; services[Network Services]; end subgraph control_plane[Control Plane: api.on-prem.net] control_plane[Control Plane]; 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.
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)