Updated on 2024-08-15 GMT+08:00

Using a DDS Trigger

This section describes how to create a DDS trigger for a function, and invoke the function when a database table changes.

A function using a DDS trigger will be triggered every time a database table is updated. For details about the DDS event source, see Supported Event Sources.

Prerequisites

Before creating a trigger, ensure that you have prepared the following:

Creating a DDS Trigger

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click the function to be configured to go to the function details page.
  3. Choose Configuration > Triggers and click Create Trigger.

    Figure 1 Creating a trigger

  4. Set the following parameters:

    • Trigger Type: Select Document Database Service (DDS).
    • DB Instance: Select a DDS DB instance.
    • Password: Enter the password of DDS DB instance administrator rwuser.
    • Database: Enter the name of a database. Note that admin, local, and config are reserved database names and cannot be used here.
    • Collection: Enter the name of a database collection.
    • Batch Size: Set the number of records to be read from the database at a time.

  5. Click OK.

    After VPC access is enabled, you need to configure corresponding subnet permissions for the DDS security group. For details about how to configure VPC access, see Configuring the Network.

Configuring a DDS Event to Trigger the Function

  1. Return to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click the function to be configured to go to the function details page.
  3. On the function details page, select a version, and click Test. The Configure Test Event dialog box is displayed.
  4. Set the parameters described in Table 1 and click Save.

    Table 1 Test event information

    Parameter

    Description

    Configure Test Event

    You can choose to create a test event or edit an existing one.

    Use the default option Create new test event.

    Event Template

    Select dds-event-template.

    Event Name

    The event name can contain 1 to 25 characters and must start with a letter and end with a letter or digit. Only letters, digits, underscores (_), and hyphens (-) are allowed. For example, dds-123test.

    Event data

    The system automatically loads the built-in DDS event template, which is used in this example without modifications.

  5. Click Test. The function test result is displayed.