Add One

The simplest possible lambda takes a numeric input, and adds one to it.

Initial Provisioning

graph LR;

subgraph user_edge[User Edge]
cli[CLI];
end

subgraph cloud[Cloud <small>api.on-prem.net</small>]
control_plane[Control Plane];
end

subgraph device_edge[Device Edge]
agent[Agent];
end

cli --> control_plane;
control_plane <-- tunnel --> agent;

Subsequent Operation

graph LR;

subgraph user_edge[User Edge]
cli[CLI];
end

subgraph device_edge[Device Edge]
agent[Agent];
end

subgraph cloud[Cloud <small>api.on-prem.net</small>]
control_plane[Control Plane];
end

cli -- input --> control_plane;
cli <-- output --- control_plane;

control_plane -- input --> agent;
control_plane <-- output --- agent;

Lua

$ onprem generate xid
d3238k9caq0nmbcvrc30
# add_one.yaml
id: d3238k9caq0nmbcvrc30
kind: Lambda
name: add_one
description: >
  Add 1.
runAt:
  deviceId: ci2fabp32ckvhk1g9qe0
scriptContentType: Lua
script: >
  local M={}
  
  function M.handler(event)
    return event + 1
  end
  
  return M
$ onprem apply add_one.yaml

JavaScript

# add_one.yaml
id: d3238k9caq0nmbcvrc30
kind: Lambda
name: add_one
description: >
  Add 1.
runAt:
  deviceId: ci2fabp32ckvhk1g9qe0
scriptContentType: JavaScript
script: >
  export const handler = async(event, context) => {
    return event + 1;
  };
$ onprem apply add_one.yaml

Run it:

$ onprem run lambda d3238k9caq0nmbcvrc30 --event 123
124.0

Lua + WASM

See the Call WASM example.


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