Route events to an API destination

更新时间:
复制 MD 格式

You can use an event rule to filter events and route them to an API destination. This topic describes the prerequisites, procedure, and result verification for routing a custom event to an API destination.

Prerequisites

Step 1: Add a custom event source

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

  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the target custom event bus.

  3. In the navigation pane on the left, click Event Source, and then click Add Event Source.

  4. In the Add Custom Event Source panel, enter a Name and Description, set Event Provider to Custom Application, and then click OK.

Step 2: Create an event rule

Important

The target service and the event rule must be in the same region.

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

  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the target event bus.

  3. In the navigation pane on the left, click Event Rules, and then click Create Rule.

  4. On the Create Rule panel, complete the following steps, and then click Create.

    1. On the Configure Basic Info tab, enter a Name and Description for the rule, and then click Next.

    2. On the Configure Event Pattern tab, set Event Source Type to Custom Event Sources, select the event source you created, and then click Next.

    3. On the Configure Targets tab, configure the following parameters and click Create.

      1. Set Service Type to Triggered by API Operation.

      2. In the Basic Information section, configure the parameters as follows.

        Parameter

        Example

        Description

        Creation method

        Create Custom

        Specifies how to create the API destination. Valid values:

        • Create Custom: Creates an API destination on the current page.

        • Use existing: If you select this option, you must create an API destination in advance. For more information, see Create an API destination.

        API destination name

        testAPI

        The name of the API destination.

        Description

        Not configured

        The description of the API destination. This parameter is optional.

        HTTP parameters

        • Parameter: Header

        • Key: Content-Type

        • Value: multipart/form-data

        You can configure the Parameter in the following ways:

        • Header: Passes metadata in the request header. This option must be configured as a key-value pair.

        • Body: Passes data in the request body. This option supports configuration as a key-value pair or as Message Raw Data.

        • Query: Passes parameters in the URL query string. This option must be configured as a key-value pair.

        Parameter values can be configured in the following ways:

        • For a key-value pair, the Key supports Partial Event, Fixed Value, or Complete Event. The Value also supports Partial Event, Fixed Value, or Complete Event.

        • Raw data: You must configure Variables and a Template. For more information, see Templates.

      3. In the API Configuration section, set the following parameters.

        Parameter

        Example

        Description

        URL

        https://******

        The endpoint URL of the API.

        HTTP method

        GET

        The HTTP request method. Valid values:

        • GET: Requests information from a specified resource and returns the entity body.

        • POST: Submits data to a specified resource for processing.

        • PUT: Uploads the latest content to a specified resource location.

        • PATCH: Applies partial modifications to a resource.

        • DELETE: Deletes a specified resource.

        • HEAD: Similar to a GET request, but the server returns only the status line and headers, not the message body.

      4. In the Connection section, set the following parameters.

        Parameter

        Example

        Description

        Configuration method

        Create New

        Specifies how to configure the connection. Valid values:

        • Create New: Creates a new connection on the current page.

        • Select an existing one: If you select this option, you must create a Connection in advance. For more information, see Create a Connection.

        Connection name

        Connection-test

        A custom name for the connection.

        Description

        Not configured

        The description of the connection. This parameter is optional.

        Authentication

        Not required

        The authentication method. Valid values:

        • Not required: No authentication is required.

        • Basic: Basic authentication. You must specify a Username and Password.

        • OAuth Client Credentials: A secure and reliable authorization method that uses OAuth 2.0 client credentials.

        • API Key: A simple authentication method. You must specify the KeyName and KeyValue.

        Network type

        Internet

        The network type. Valid values:

      5. (Optional) Expand the Retry Policy and Dead-letter Queue section to configure the Retry Policy, Fault Tolerance Policy, and Dead-letter Queue. For more information, see Retry policies and dead-letter queues.

Step 3: Publish an event

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

  2. In the top navigation bar, select a region.

  3. On the Event Buses page, find the target event bus and click Publish Event in the Operations column.

    Note

    In the EventBridge console, you can publish events only to custom event buses.

  4. In the Publish Event to Custom Event Bus {name} panel, select the custom event source you created from the Custom Event Source drop-down list, enter the event content in the Event Body code editor, and then click OK.

    Note
    • For more information about the event structure, see Event overview.

    • After you click OK, the event ID is automatically copied.

Verify the result

  1. Go to the Overview page of the target event bus.

  2. In the navigation pane on the left, click Event Tracking, and then click the Query By Event ID tab.

  3. In the Event ID field, paste the copied event ID and click Query.

  4. Find the queried event and click Event Trace in the Actions column to check whether the event was successfully delivered.

    On the event trace details page, check the Event Delivery section. If the rule's delivery status is Success, the event was delivered to the API destination.