Help Center/ EventGrid/ Getting Started/ Sending a Huawei Cloud Service Event
Updated on 2023-10-26 GMT+08:00

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

Step 1: Create an Event Target (Create a Function)

  1. Log in to the FunctionGraph console.
  2. Choose Functions > Function List in the navigation pane.
  3. Click Create Function.
  4. 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.
    Figure 1 Creating a function

  5. Click Create.
  6. 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.

  1. Log in to the EG console.
  2. In the navigation pane, choose Event Subscriptions.
  3. Click Create Event Subscription.
  4. Click next to the default subscription name.
  5. Enter OfficialEvent in Subscription Name, and click OK.
  6. Configure an event source.

    1. 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.
      Figure 2 Setting event source parameters
    2. Click OK.

  7. Configure an event target.

    1. Click Event Target, and set event target parameters as shown in Figure 3.
      • Provider: Select Huawei Cloud.
      • Event Target: Select FunctionGraph (function computing).
      • Function: Select test (created in Step 1).
      • Version: Select latest.
      • Transform Type: Select Pass-through.
      Figure 3 Setting event target parameters
    2. Click OK.

  8. Click Save.

Step 3: Generate an OBS Event (Create an OBS Bucket)

  1. Log in to the OBS console.
  2. Click Create Bucket.
  3. 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.
    Figure 4 Creating a bucket

  4. Click Create Now and create a bucket as prompted.

Step 4: View Results

  1. Log in to the FunctionGraph console.
  2. Choose Functions > Function List in the navigation pane.
  3. Click the test function to go to the function details page.
  4. On the Metrics tab page, view the number of invocations and running duration.

    Figure 5 Viewing metrics