Invoke a Function at the Edge

Manually

A deployed function can be invoked manually by running the following API request (see OpenAPI documentation for more details):
`POST /support/faas/functions` 

With request body that the function code expects.

On a Schedule

Functions can be invoked on a schedule using a cron format. In this case there will be no request body. An optional callback URL can be used where the result can be posted (no auth possible on the callback URL).

The schedule can be set up using the following API request:
`POST /functions/faas/schedules` 
With request body:
``` 
{ 
 "function": "<function-name>", 
 "cron": "0 * * * *", 
 "callback_url": "https://example.com/callback" 
} 
``` 

On a Telemetry Trigger

There are two parts to having a function triggered on telemetry data:
  • A so-called trigger needs to be defined for specific topics
  • The function itself needs to have the topics added on creation or update

A trigger basically defines which topics should have telemetry data used to invoke functions. Each function using that topic will be invoked.

A trigger can be created using the following API request:
`POST /functions/faas/triggers` 
With request body:
``` 
{ 
 "topics": [ 
 "things/<thing-uid>/properties" 
 ], 
 "callback_url": "https://example.com/callback" 
} 
``` 

The callback URL is optional, like it is for schedules.

The topics need to be one of the following formats:
  • things/{thing-uid}/properties
  • things/{thing-uid}/properties/{property-key}
  • things/{thing-uid}/actions
  • things/{thing-uid}/actions/{action-key}
  • things/{thing-uid}/events
  • things/{thing-uid}/events/{event-key}

The + wildcard is supported for the thing-uid, property-key, action-key, and event-key. When not using a wildcard, the key needs to exist at the edge.

In addition to the telemetry data passed in the request body when invoking a function the following headers are added when available:
  • X-Thing-ID (the thing’s UID)
  • X-Message-Type (properties/actions/events)
  • X-Message-Key (the property key, action key or event key)