You can route events to Function Compute by using event rules. This topic describes
the prerequisites, procedure, and result verification of routing custom events to
Function Compute.
Prerequisites
The following operations are performed:
Step 1: Create a custom event bus
To create a custom event bus to receive events from your applications, perform the
following steps:
- Log on to the EventBridge console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Custom Event Buses.
- On the Custom Event Buses page, click Create Event Bus.
- In the Create Event Bus panel, specify Name and Description, for example, set Name to MyEventBus and enter Used for Receiving Custom Application Events in the Description field. Then, click OK.
Step 2: Publish an event
- Log on to the EventBridge console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Custom Event Buses.
- On the Custom Event Buses page, find the required event bus and click Publish Event in the Operations column.
Note You can publish events only to custom event buses in the EventBridge console.
- In the Publish Event to Custom Event Bus panel, enter the event content in the code editor and click OK.
For more information about the event parameters, see
Overview.
Step 3: Create an event rule
- Log on to the EventBridge console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Custom Event Buses.
- On the Custom Event Buses page, find the required event bus and click Rules in the Operations column.
- On the Rules page, click Create Rule.
- On the Create Rule page, perform the following steps:
- In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field, and then click Next Step.
- In the Configure Event Pattern step, select Customized Pattern for Event Pattern Type, specify the event pattern in the Event Pattern Content section, and then click Next Step.
- In the Configure Targets step, configure an event target.
Notice Make sure that the event target and the event rule are in the same region.
- Click Create.
Verify the result
To verify the result, you can view logs in the Function Compute console.
- Log on to the Function Compute console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Service/Function.
- On the Service/Function page, click the service. Then, click the function name in the Function Name column on the Functions tab.
- On the page that appears, click the Log tab to view logs.
FC Invoke Start RequestId: c2be67a7-fh1a-9619-ei4c-3c04gcf6****
2020-11-19T11:11:34.161Z c2be67a7-fh1a-9619-ei4c-3c04gcf6c**** [verbose] Receive Event v2 ==> The event comes from aliyun.ui,event type is ui:Created:PostObject.
2020-11-19T11:11:34.167Z c2be67a7-fh1a-9619-ei4c-3c04gcf6c****
FC Invoke End RequestId: c2be67a7-fh1a-9619-ei4c-3c04gcf6c****