All Products
Search
Document Center

EventBridge:Create a custom event source of the API Gateway type

Last Updated:Jan 12, 2024

This topic describes how to create a custom event source of the API Gateway type in the EventBridge console.

Prerequisites

Step 1: Create a backend service

  1. Log on to the API Gateway console. In the left-side navigation pane, choose Open API > Backend Services.

  2. 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.

    Custom event source of the API Gateway type

  3. 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.

  4. On the Backend Service Definition page, click the Production tab. In the Basic Information section, click Create.

  5. 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

  1. Log on to the API Gateway console. In the left-side navigation pane, choose Open API > API Groups.

  2. 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.

    Create an API group

    Important

    The 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.

  1. In the Basic Information step, configure the following parameters and click Next.

    Basic information

  2. In the Define API Request step, configure the following parameters and click Next.

    Define an API request

    Note

    In 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.

  3. In the Define Backend Service step, set the parameters and click Next.

    Backend service information

  4. (Optional) On the Define Response tab, configure the Response Example and Error Response Example parameters to generate API help documentation and click Create.

  5. 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

  1. Log on to the API Gateway console. In the left-side navigation pane, choose Call API > Apps.

  2. 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.

  3. Go back to the APIs page, find the API that you created in Step 3: Create an API, and choose More > Authorize in the Actions column.

  4. 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.

    Add an application

Step 5: Debug an API

  1. On the Apps page, find the API that you created in Step 3: Create an API and click Debug in the Actions column.

  2. 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.

    Send a request

View event details

  1. Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.

  2. On the Event Buses page, click the name of the custom event bus that you want to manage.

  3. 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.