This topic describes how to create a custom event source of the API Gateway type in the EventBridge console.
Prerequisites
EventBridge is activated and the required permissions are granted to a Resource Access Management (RAM) user. For more information, see Activate EventBridge and grant permissions to a RAM user.
A custom event bus is created. For more information, see Create a custom event bus.
Step 1: Create a backend service
Log on to the API Gateway console. In the left-side navigation pane, choose .
In the upper-right corner of the Backend Services page, click Create Backend Service. In the Create Backend Service dialog box, enter the name of the backend service, select EventBridge from the Type drop-down list, and then click Confirm.
In the backend service list, find the backend service that you created and click Configure Backend Service and View Associated APIs in the Actions column.
On the Backend Service Definition page, click the Production tab. In the Basic Information section, click Create.
On the Define Backend Service page, select the region where the custom event bus is created from the Region drop-down list, select the name of the custom event bus from the Event Bus drop-down list, specify the name and description of the event source, and then click Publish.
Step 2: Create an API group
In the left-side navigation pane, choose
.In the upper-right corner of the API Groups page, click Create Group, select an instance from the Instances drop-down list, configure the Group Name parameter, and then click Confirm.
ImportantThe API group that you create must reside in the same region as the custom event bus that you created in the "Prerequisites" section.
Step 3: Create and authorize an API
On the API Groups page, find the API group that you created in Step 2, click Manage APIs in the Actions column.
On the APIs page, click Create API.
In the Basic Information step, configure the parameters and click Next.
In the Define API Request step, configure the parameters and click Next.
NoteIn this step, you can define how EventBridge calls the API. You need to specify the request type, protocol, request path, HTTP method, request mode, and request parameters.
In the Define Backend Service step, configure the Backend Service Type and Backend Service parameters and click Next.
(Optional) On the Define Response tab, configure the Response Example and Error Response Example parameters to generate API help documentation and click Create.
After the API is created, click Publish in the Actions column to publish the API to the production environment.
In the APIs page, find the API that you want to manage and click the icon in the Actions column. Then, click Authorize.
In the Authorize panel, specify the authorization validity period and the apps that you want to authorize. Then, click Confirm.
Step 5: Debug the API
On the APIs page, find the API that you created in Step 3: Create and authorize an API and click Debug in the Actions column.
On the Debug API page, select Production as the debugging environment, set the Verification Method parameter to Use AppCode, configure the request parameters, and then click Send Request.
View the details of an event
Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.
On the Event Buses page, click the name of the custom event bus that you want to manage.
In the left-side navigation pane, click Event Tracking, select the Query By Time Range or Query By Event ID tab, configure the corresponding parameters, and then click Query.
Click Event Detail in the Operations column to view the content of the event.
The following sample code provides an example of queried events:
{ "datacontenttype": "application/json", "aliyunaccountid": "1431999136******", "data": { "headers": { "Authorization": "APPCODE 0624849af6ab4020a272fe9f7b******", "Proxy-Uid": "X-Ca-e605e437-b65d-4e52-9f8c-515c55******", "X-Ca-Stage": "RELEASE", "User-Agent": "Apache-HttpClient/4.5.6 (Java/1.8.0_172)", "Accept-Encoding": "gzip,deflate", "Content-Type": "text/html" }, "path": "/test/eb/1", "pathParameters": {}, "method": "GET", "queryParameters": {} "body": "" }, "aliyunoriginalaccountid": "143199913******", "source": "time-source-ad2a0405-9a2a-4f86-87f1-c0ef89******", "type": "eventbridge:Events:ApiGateway", "aliyunpublishtime": "2024-11-14T07:11:33.287Z", "specversion": "1.0", "aliyuneventbusname": "ad2a0405-9a2a-4f86-87f1-c0ef89******", "id": "324213ab-cae5-4049-89a4-560ead******", "time": "2024-11-14T07:11:33.000Z", "aliyunregionid": "cn-hangzhou", "aliyunpublishaddr": "172.20.XX.XX" }
For more information about the parameters defined in the CloudEvents specification, see Overview.
The following table describes the parameters contained in the data field.
Parameter
Required
Example
Description
headers
Map
{ "Authorization": "APPCODE b6e439f27045443ca58e9136ef20****", "X-Ca-Dashboard-Uid": "115964845466****", "X-Ca-Dashboard-Action": "DEBUG", "X-Ca-Stage": "RELEASE", "X-Ca-Dashboard-Role": "USER", "User-Agent": "Apache-HttpClient/4.5.6 (Java/1.8.0_172)", "Accept-Encoding": "gzip,deflate", "Content-Type": "text/html; charset=utf-8" }
The HTTP request header.
path
String
/test/eb/1
The HTTP request path.
pathParameters
Map
None
The path parameters.
body
String/Map
None
The HTTP request body. If the value of the Content-Type parameter is application/json, the HTTP request body is parsed as a JSON object. Otherwise, the HTTP request body is parsed as a common string.
method
String
GET
The HTTP request method.
queryParameters
Map
None
The value of the query parameter in the HTTP request, excluding the content of the token parameter.