Using a CTS Trigger
For details about the CTS event source, see Supported Event Sources.
Prerequisites
You have created an agency on IAM. For details, see Creating an Agency.
Creating a CTS Trigger
- Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
- Click Create Function.
- Set the following parameters:
- Template: Select Create from scratch.
- Function Name: Enter a function name, for example, HelloWorld.
- Enterprise Project: Select default.
- Agency: Select Use no agency.
- Runtime: Select Python 2.7.
- Click Create Now.
- On the Code tab page, copy the following code to the code window and 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)
- Choose Configuration > Triggers and click Create Trigger.
- Configure the trigger information.
Table 1 Trigger information Parameter
Description
Trigger Type
Select Cloud Trace Service (CTS).
Notification Name
Enter a notification name, for example, Test.
Service Type
Select FunctionGraph.
Resource Type
Resource types supported by the selected service, such as triggers, instances, and functions.
Trace Name
Operations that can be performed on the selected resource type, such as creating or deleting a trigger.
NoteA maximum of 10 services, each with up to 10 operations, can be added for each CTS trigger. The total number of operations cannot exceed 100. For details, see Supported Services and Operation Lists.
- Click OK.
Configuring a CTS Event to Trigger the Function
- On the function details page, click the Code tab and select Configure Test Event.
- Set the parameters described in Table 2 and click Save.
Table 2 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 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.
- Click Test.
- Prerequisites
- Creating a CTS Trigger
- Configuring a CTS Event to Trigger the Function