All Products
Search
Document Center

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

Last Updated:Nov 26, 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 Manage APIs > Backend Services.

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

    12Kka09sbi

  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. In the left-side navigation pane, choose Manage APIs > API Groups.

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

    SYIFxEn5sG

    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 and authorize an API

  1. On the API Groups page, find the API group that you created in Step 2, click Manage APIs in the Actions column.

  2. On the APIs page, click Create API.

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

      bmVHlylxnB

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

      EVRUdrh91I

      Note

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

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

      aURupKIZw0

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

  3. After the API is created, click Publish in the Actions column to publish the API to the production environment.

  4. In the APIs page, find the API that you want to manage and click the image icon in the Actions column. Then, click Authorize.

  5. In the Authorize panel, specify the authorization validity period and the apps that you want to authorize. Then, click Confirm.

    677dXHeo82

Step 5: Debug the API

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

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

    IpYBZq1PhH

View the details of an event

  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 or Query By Event ID tab, configure the corresponding parameters, and then click Query.

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