This topic describes how to create a custom event source of the API Gateway type in the EventBridge console.
Prerequisites
EventBridge is activated and permissions are granted to a 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 Manage custom event buses.
Step 1: Create a backend service
Log on to the API Gateway console. In the left-side navigation pane, choose .
On the Backend Services page, click Create Backend Service in the upper-right corner. 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
Log on to the API Gateway console. In the left-side navigation pane, choose .
On the API Groups page, click Create Group in the upper-right corner, 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 an API
On the API Groups page, find the API group that you created in Step 2: Create an API group, click Manage APIs in the Actions column, and then click Create API.
In the Basic Information step, configure the following parameters and click Next.
In the Define API Request step, configure the following parameters and click Next.
NoteIn this step, you can define how EventBridge calls the API operation. The parameters that you must configure include Request Type, Protocol, Request Path, HTTP Method, and Request Mode.
In the Define Backend Service step, set the 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.
Step 4. Create an application and authorize an API operation
Log on to the API Gateway console. In the left-side navigation pane, choose .
On the Apps page, click Create App in the upper-right corner. In the Create App dialog box, configure the App Name and Description parameters and click Confirm.
Go back to the APIs page, find the API that you created in Step 3: Create an API, and choose in the Actions column.
Set the Stage parameter to Production, configure the Authorization Validity Period parameter, enter the name of the application that you created in the search box, and then click Search. In the search result that appears, click Add in the Actions column, and then click Confirm.
Step 5: Debug an API
On the Apps page, find the API that you created in Step 3: Create an API and click Debug in the Actions column.
On the Debug API page, select Production as the debugging environment, set the Verification Method to Use AppCode, configure the request parameters, and then click Send Request.
View event details
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 tab or the Query By Event ID tab, configure the corresponding parameters, and then click Query to view the event details.
The following code shows the details of the queried event:
{ "datacontenttype": "application/json", "aliyunaccountid": "115964845466****", "data": { "headers": { "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" }, "path": "/test/eb/1", "pathParameters": {}, "method": "GET", "queryParameters": {}, "body": "" }, "aliyunoriginalaccountid": "115964845466****", "source": "testAPI", "type": "eventbridge:Events:ApiGateway", "aliyunpublishtime": "2022-11-14T07:38:01.409Z", "specversion": "1.0", "aliyuneventbusname": "mybus", "id": "72db5348-61e8-404c-85be-cee24176****", "time": "2022-11-14T07:38:01Z", "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 data.
Parameter
Type
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 header of the HTTP request.
path
String
/test/eb/1
The path of the HTTP request.
pathParameters
Map
None
The path parameters.
body
String/Map
None
The body of the HTTP request. If the value of the Content-Type parameter is application/json, the body of the HTTP request is parsed as a JSON object. Otherwise, the 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.