Sending a Custom Event
This section describes how to send a custom event.
The custom events generated by custom event sources are sent to EG. The EG service filters and converts the custom events based on the filter rule, and triggers the event target (a function in FunctionGraph).
Prerequisites
- You have completed the operations in Enabling EG and Authorizing Permissions.
- You have obtained the permission to access FunctionGraph.
Step 1: Create a Custom Channel
- Log in to the EG console.
- In the navigation pane, choose Event Channels.
- Click Create Event Channel.
- Enter channel in Name, and click OK.
View the created channel in the Custom area, and record the channel ID.
Figure 1 Event channel ID
Step 3: Create an Event Target (Create a Function)
- Log in to the FunctionGraph console.
- Choose Functions > Function List in the navigation pane.
- Click Create Function.
- Set function parameters, as shown in Figure 3. For details about the function parameters, see Creating a Function.
- Function Type: Select Event Function.
- Region: Select the region as required.
- Function Name: Enter test.
- Agency: Select Use no agency.
- Runtime: Select Python 2.7.
- Click Create.
- On the Code tab page of the function details page, enter the following code and click Deploy.
# -*- coding:utf-8 -*- import json def handler (event, context): print(json.dumps(event)) return { "statusCode": 200, "isBase64Encoded": False, "body": json.dumps(event), "headers": { "Content-Type": "application/json" } }
Step 4: Create an Event Subscription
Subscriptions bind event sources, channels, and targets. Events of sources are routed to targets based on specified rules.
- Log in to the EG console.
- In the navigation pane, choose Event Subscriptions.
- Click Create Event Subscription.
- Click next to the default subscription name.
- Enter CustomEvent in Subscription Name, and click OK.
- Configure an event source.
- Click Event Source, and set event source parameters as shown in Figure 4.
- Provider: Select Custom.
- Channel type: Select Existing for Type.
- Channel configuration: Select the channel created in Step 1 from Channel.
- Event source type: Select Existing for Type.
- Event source configuration: Select egsdk-source (created in Step 2) from Event Source.
- Filter Rule: Retain the default value and record the value of values, for example, egsdk-source in Figure 4.
- Click OK.
- Click Event Source, and set event source parameters as shown in Figure 4.
- Configure an event target.
- Click Save.
Step 6: View Results
- Log in to the FunctionGraph console.
- Choose Functions > Function List in the navigation pane.
- Click the test function to go to the function details page.
- On the Metrics tab page, view the number of invocations and running duration.
Figure 6 Viewing metrics
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot