Updated on 2025-08-19 GMT+08:00

Cloud Trace Service (CTS) Trigger

This section describes how to create a CTS trigger for a function, and invoke the function in response to cloud resource operations recorded by CTS.

Overview

Cloud Trace Service (CTS) is a log audit service for cloud security. It allows you to collect, store, and query operation records of cloud resources for security analysis, compliance auditing, resource tracking, and fault locating.

With a CTS trigger, you can create a function to subscribe to event notifications based on the CTS service type and operation. Collected operation records will be passed as a parameter (CTS example event) to invoke the function. Then, the function analyzes and processes key information in the operation records, automatically recovers system or network modules, or reports alarms to service personnel by SMS or email.

You can configure CTS triggers for shared functions in the LA-Sao Paulo1 region.

Notes and Constraints

  • Currently, CTS triggers are available in all regions except AP-Jakarta, AF-Johannesburg, and LA-Santiago. You can check whether the trigger type is supported on the console.

Prerequisites

You have configured the CTS agency permission for the function. For details, see Configuring Agency Permissions.

Creating a CTS Trigger

The following procedure describes how to configure a CTS trigger for a Python function.

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. On the Function List page, click Create Function in the upper right corner.
  3. Set the following parameters:
    • Function Name: Enter a function name, for example, HelloWorld.
    • Agency: Select an agency that has the CTS permissions.
    • Enterprise Project: Select default.
    • Runtime: Select Python 2.7.
  4. Click Create Function.
  5. On the Code tab page, copy the following code to the code editing area. For details about parameters, see Table 2. Then, click Deploy.
    # -*- coding:utf-8 -*-
    '''
    CTS trigger event:
    {
      "cts":  {
            "time": "",
            "user": {
                "name": "userName",
                "id": "",
                "domain": {
                    "name": "domainName",
                    "id": ""
                }
            },
            "request": {},
            "response": {},
            "code": 204,
            "service_type": "FunctionGraph",
            "resource_type": "",
            "resource_name": "",
            "resource_id": {},
            "trace_name": "",
            "trace_type": "ConsoleAction",
            "record_time": "",
            "trace_id": "",
            "trace_status": "normal"
        }
    }
    '''
    def handler (event, context):
        trace_name = event["cts"]["resource_name"]
        timeinfo = event["cts"]["time"]
        print(timeinfo+' '+trace_name)
    Table 2 Parameters

    Parameter

    Description

    time

    The value is a 13-digit timestamp, for example, 1738805309469.

    record_time

    The value is a 13-digit timestamp, for example, 1738805309469.

  6. Choose Configuration > Triggers and click Create Trigger.
    Figure 1 Creating a trigger
  7. Configure the following parameters.
    Table 3 Parameters for creating a CTS trigger

    Parameter

    Description

    Example Value

    Trigger Type

    Mandatory.

    Select Cloud Trace Service (CTS).

    Select Cloud Trace Service (CTS).

    Event Notification Name

    Mandatory.

    Notification name of the CTS trigger. The value can contain a maximum of 64 characters, including letters, digits, and underscores (_).

    CTS_fg

    Custom Operations

    Mandatory.

    A maximum of 10 services and 100 operations can be added. The parameters are as follows:

    • Service Type: Select FunctionGraph.

      If Service Type is set to a global cloud service, such as OBS or IAM, CTS triggers can be triggered only in CN-Hong Kong. For details about global cloud services, submit a service ticket.

    • Resource Type: The resource type of the selected service, such as trigger, instance, and function.
    • Trace Name:Operations that can be performed on the selected resource type, such as creating or deleting a trigger.

    FunctionGraph; Functions; createFunction

  8. Click OK.

Configuring a CTS Trigger for a Shared Function

You can configure a CTS trigger for a shared function in the LA-Sao Paulo1 region. For details about the shared function, see Sharing Functions Based on RAM.

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. On the Shared tab, click the function name to go to the function details page.
  3. The subsequent steps are the same as those for creating a common function. For details, see 6.

Configuring a CTS 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 4 and click Save.

    Table 4 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 Templates

    Select Cloud Trace Service (CTS) and use the built-in CTS event template.

    Event Name

    Enter an event name, for example, cts-test.

    Event data

    The system automatically loads the event data in the CTS event template. You can modify the event data as required.

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

Helpful Links

Manage function triggers through APIs. For details, see Function Trigger APIs.