HomeServerlessFunctionsHow to
add trigger to a function
Jump toUpdate content

How to add a trigger to a function

Reviewed on 27 April 2023Published on 27 April 2023

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.

Requirements:
Important:

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.

  1. Click Functions in the Serverless section of the side menu. The functions page displays.
  2. Click the relevant functions namespace.
  3. Click the name of the function you want to manage. The function overview displays.
  4. Click the Triggers tab. The trigger configuration displays.
  5. Click Create new Trigger. The trigger creation form displays in a pop-up.
  6. 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.
  7. Click Create trigger to launch trigger creation.
  8. 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.

  1. Click Functions in the Serverless section of the side menu. The functions page displays.
  2. Click the relevant functions namespace.
  3. Click the name of the function you want to manage. The function overview displays.
  4. Click the Triggers tab. The trigger configuration displays.
  5. Click Create new Trigger. The trigger creation form displays in a pop-up.
  6. 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.
  7. Click Create trigger to launch trigger creation.