Lambda Triggers
Lambda Triggers provide a way to generate events that Lambdas can respond do. Every Lambda Trigger is expected to run a control loop, and is given a dedicated thread in the agent or control plane.
When creating a new Lambda Trigger in the web console, number of templates are offered:
Structure of a Lambda Trigger
A Lambda Trigger contains an initialization function which can be used to perform resource allocations. A context object is made available and can be used for temporary storage.
Then a Lambda Trigger provides a run function, which should emit events that will be delivered to Lambdas.
local redis = require('redis')
local socket = require('socket')
local M = {}
function M.init(context, params)
local redis_client = redis.connect('my-redis', 6379)
assert(redis_client:ping())
context['redis_client'] = redis_client
end
function M.run(context)
local redis_client = context.redis_client
local channels = {'foo', 'bar'}
for msg, abort in redis_client:pubsub({subscribe=channels}) do
local event = {
timestamp = socket.gettime(),
msg = msg
}
coroutine.yield(event)
end
end
return M