Read this on the main serverless docs site¶
Triggers¶
Functions are connected to event sources in OpenWhisk using triggers and rules. Triggers create a named event stream within the system. Triggers can be fired manually or connected to external data sources, like databases or message queues.
Rules set up a binding between triggers and serverless functions. With an active rule, each time a trigger is fired, the function will be executed with the trigger payload.
Event binding using triggers and rules for functions can be configured through the serverless.yaml file.
This configuration will create a trigger called servicename-my_trigger with an active rule binding my_function to this event stream.
Customising Rules¶
Rule names default to the following format servicename-trigger-to-action. These names can be explicitly set through configuration.
Customising Triggers¶
Triggers can be defined as separate resources in the serverless.yaml file. This allows you to set up trigger properties like default parameters.
functions:
my_function:
handler: index.main
events:
- trigger: my_trigger
resources:
triggers:
my_trigger:
parameters:
hello: world
Trigger Feeds¶
Triggers can be bound to external event sources using the feed property. OpenWhisk provides a catalogue of third-party event sources bundled as packages.
This example demonstrates setting up a trigger which uses the /whisk.system/alarms/alarm feed. The alarm feed will fire a trigger according to a user-supplied cron schedule.