How to add a trigger to a function
This page shows you how to configure triggers for your functions. A trigger is an event that activates or invokes a Serverless Function. In a serverless architecture, a function is not running constantly, but is rather triggered only when there is an event. A trigger is a mechanism that connects the function to an event source and enables the function to execute automatically in response to specific events. The trigger could be anything from an HTTP request, a message from a queue or stream, a CRON schedule etc.
The trigger is configured during function deployment, and it determines how and when the function will execute.
- You have an account and are logged into the Scaleway console
- You have created a functions namespace
- You have created a function
- You have created an SQS namespace
- You have created credentials for your SQS namespace
- You have created an SQS queue
This feature is currently in beta and does not support calling private functions yet.
SQS triggers
An SQS (Simple Queue Service) trigger is a mechanism that connects a function to an SQS queue and invokes the function automatically whenever a message is added to the queue. For each message that is sent to an SQS queue, the SQS trigger reads the message and invokes the associated function with the message as the input parameter. The function can then process the message and perform any required actions, such as updating a database or sending a notification. Currently, SQS queues of the Scaleway Messaging and Queuing product are supported.
- Click Functions in the Serverless section of the side menu. The functions page displays.
- Click the relevant functions namespace.
- Click the name of the function you want to manage. The function overview displays.
- Click the Triggers tab. The trigger configuration displays.
- Click Create new Trigger. The trigger creation form displays in a pop-up.
- Enter a name for your trigger and select the SQS (Scaleway) type. Select the messaging namespace to use from the drop down name and enter your queue name.
- Click Create trigger to launch trigger creation.
- When a message is pushed to the selected queues, the function will be triggered with the message content passed in the event object’s body.
CRON triggers
A cron trigger is a mechanism for triggering a Serverless Function at a specific time or on a recurring schedule, similar to a traditional cron job on a linux server.
- Click Functions in the Serverless section of the side menu. The functions page displays.
- Click the relevant functions namespace.
- Click the name of the function you want to manage. The function overview displays.
- Click the Triggers tab. The trigger configuration displays.
- Click Create new Trigger. The trigger creation form displays in a pop-up.
- Enter a name for your trigger and select the CRON type. Enter the cron scheudule in UNIX format and paste your JSON arguments in the form.
- Click Create trigger to launch trigger creation.