Sending a Huawei Cloud Service Event
This section describes how to send a Huawei Cloud service event.
Huawei Cloud Object Storage Service (OBS) sends the generated cloud service events to EG. The EG service filters and converts the 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 OBS and FunctionGraph.
Step 1: 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 1. 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 2: 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 OfficialEvent in Subscription Name, and click OK.
- Configure an event source.
- Click Event Source, and set event source parameters as shown in Figure 2.
- Provider: Select Huawei Cloud.
- Event Source: Select Object Storage Service (OBS).
- Filter Rule: Use the default rule.
- Click OK.
- Click Event Source, and set event source parameters as shown in Figure 2.
- Configure an event target.
- Click Save.
Step 3: Generate an OBS Event (Create an OBS Bucket)
- Log in to the OBS console.
- Click Create Bucket.
- Set bucket parameters, as shown in Figure 4. For details about the bucket parameters, see Creating a Bucket.
- Region: The value must be the same as the region of the EG service.
- Bucket Name: Enter eg-test.
- Default Storage Class: Select Standard.
- Bucket Policy: Select Private.
- Default Encryption: Leave it unselected.
- Direct Reading: Select Disable.
- Enterprise Project: Select default.
- Click Create Now and create a bucket as prompted.
Step 4: 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 5 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