Creating Triggers

Last updated: 2021-10-26 15:40:39

    After creating a function, you can create a trigger to associate the function with an event source. The associated event source will trigger the function synchronously or asynchronously as specified when an event is generated, and the event will be passed to the entry function as an input parameter upon triggering.

    A function trigger can be created in the console or through Serverless Framework CLI.

    Note:

    Only API Gateway triggers can be created for HTTP-triggered functions. For more information, please see Creating HTTP-Triggered Function.

    Creating Trigger in Console

    1. Log in to the SCF console and select Function Service on the left sidebar.

    2. At the top of the Function Service page, select the region and namespace where the function for which to create a trigger resides as shown below:

      The function list contains the function name, monitoring information, runtime environment, creation time, and modification time.

    3. Click the function name to enter the function details page.
      The function details page contains the function management, trigger management, monitoring information, log query, and concurrency quota tabs:

    4. On the function details page, select Trigger Management on the left to enter the trigger browsing and operation page. Click Create a Trigger to create a trigger as shown below:

    5. In the Create a Trigger pop-up window, you can select different trigger methods in Trigger Method. The information to be entered varies by trigger method.
      For example, for a timer trigger, you need to enter the trigger name, cycle, and status. For a COS trigger, you need to enter the COS bucket, event type, and prefix/suffix filters.

      Note:

      For more information on what to enter for specific triggers, please see the applicable documents of triggers.

    6. After completing the trigger configuration, click Submit to create the trigger.

      Note:

      To cancel the creation process, click Close.

    Creating Trigger Through Serverless Framework CLI

    Note:

    Before starting, please install the Serverless Framework CLI tool first as instructed in Installing Serverless Framework.

    For local functions, please add the trigger description in the serverless.yml file. Then, run the sls deploy command on Serverless Framework CLI to add a trigger to the function.

    Version and Trigger

    A trigger can be created on a specified version of a function. An event of the trigger created in this manner will trigger the code on the specified version.

    When creating such a trigger in the console, you can switch to the desired version by choosing it in the version list in the top-right corner on the function page and then create the trigger on the "Triggers" tab.

    Note:

    There are certain quota limits for the total number of triggers and number of triggers in each type for a function. Based on the function configuration, triggers created on different versions take up the quota of the function. To increase the limit, please contact us for application.