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.
- App: Select default.
- Agency: Select Use no agency.
- Description: Enter additional information about the function. This parameter is optional.
- Runtime: Select Python 2.7.
- Handler: Enter index.handler.
- Code Entry Mode: Select Edit code inline, enter the following code, and set the parameters to the actual values.
# -*- 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)
- Click Create Now.
- On the Triggers tab page, 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.
A 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 displayed function details page, select a version and choose Select test event > 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 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.
Last Article: Using an LTS Trigger
Next Article: Using a DDS Trigger
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.