Create a Function
- Under Functions, click Workers.
-
Click New Worker.
-
Enter the Function's name and description (optional).
-
Create your own Serverless Function by coding it. Currently, you can do this
using Python or Go by choosing the appropriate language template.
Each template gives you a basic structure to find a single Function within which all the tasks must run. This is your main Function, and everything starts and ends with it. You can (and probably should) use auxiliary Functions to refactor your code, but make sure the main Function is there. Please don't rename it or change its definition.
This main Function has some input parameters that will give you the context of the HTTP request made to invoke the function:
- Path
- Method (POST, GET, PUT, PATCH, or DELETE)
- Headers
- Query Parameters
- Body
This information is the data you can provide to your Function.
When the task of your Function has finished, return some result or feedback in your response. For this you can:
- Set a status code
- Use the response body
- Add headers to the response
The details on how to get the request data and how to set the response info is language and template specific, so check the documentation about the template you want to use to build your Function:
- Go template documentation
- Python template documentation
-
Select the appropriate template (GO or Python 3).
The code appears in the panel.
-
To have your function be subscribed to an Event Trigger so that you can capture
events and messages from different sources and redirect them to your Function,
under Event Trigger, click Add Topic and enter the MQTT
topic.
-
To schedule your functions’ invocation, enter a Cron Expression in the
field.
Check here for Cron expressions requirements.
- Click Save.