All Products
Search
Document Center

EventBridge:Route events to API destinations

Last Updated:Dec 31, 2024

You can use event rules to filter events and route the events to API destinations. This topic describes the prerequisites and procedure for routing custom events to API destinations. This topic also describes how to verify the result.

Before you start

Step 1: Create a custom event source

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

  2. In the top navigation bar, select a region. 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 Sources and then click Add Event Source.

  4. In the Add Custom Event Source panel, configure the Name and Description parameters, select Custom Application from the Event Provider drop-down list, and then click OK.

Step 2: Create an event rule

Important

The event targets that you want to configure for an event rule must reside in the same region as the event rule.

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

  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the event bus that you want to manage.

  3. In the left-side navigation pane, click Event Rules. On the page that appears, click Create Rule.

  4. In the Create Rule wizard, perform the following steps and click Create:

    1. In the Configure Basic Info step, configure the Name and Description parameters and click Next Step.

    2. In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source, select the created event source from the Event Source drop-down list, and then click Next Step.

    3. In the Configure Targets step, configure the parameters and click Create.

      1. Set the Service Type parameter to Triggered by API destination.

      2. In the Basic Information section, configure the parameters. The following table describes the parameters.

        Parameter

        Example

        Description

        Method

        Custom

        The method that you want to use to create an API destination. Valid values:

        • Create Custom API Destination: If you select this method, you must create an API destination in the current panel.

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

        API Destination Name

        testAPI

        The name of the custom API destination.

        Description

        None.

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

        HTTP Parameter

        • Parameter: Header

        • Key: Content-Type

        • Value: multipart/form-data

        The HTTP parameters. Valid values for the Parameter parameter:

        • Header: Metadata is transmitted by using headers. Headers must be key-value pairs.

        • Body: Data is transmitted by using request bodies. Request bodies can be key-value pairs or raw data.

        • Query: Parameters are passed by querying strings in URLs. Strings must be key-value pairs.

        The following items describe the detailed configuration method for the Parameter parameter:

        • If you select Form Data, the following values are available for the Key and Value parameters: Partial Event, Fixed Value, and Complete Event.

        • If you select Raw Data, you must configure the variables and template in the Variables and Template code editor. For more information, see Template.

      3. In the API Configuration section, configure the parameters. The following table describes the parameters.

        Parameter

        Example

        Description

        URL

        https://******

        The API URL of the server resource that you want to access.

        HTTP Method

        GET

        You can use one of the following methods to obtain the server resource:

        • GET: requests the specified resource and returns the entity body.

        • POST: submits data included in the request body to the specified resource and requests the server to process the data.

        • PUT: uploads the most recent content of the specified resource to a specific location.

        • PATCH: modifies part of the content of the specified resource.

        • DELETE: requests the server to delete the specified resource.

        • HEAD: a method that is similar to the GET method. If you use this method, only the status row and header information are returned by the server.

      4. In the Connection Configuration section, configure the parameters. The following table describes the parameters.

        Parameter

        Example

        Description

        Method

        Create Connection

        The method that you want to use to create the connection. Valid values:

        • Create Connection: If you select this method, you must create a connection in the current panel.

        • Select Existing Connection: If you select this method, you must create a connection in advance. For more information, see Create a connection.

        Name

        Connection-test

        The name of the connection that you want to create.

        Description

        None.

        The description of the connection. This parameter is optional.

        Authentication

        None

        The authentication method. Valid values:

        • None: no authentication. If you select this method, the API destination responds to all access requests.

        • Basic: the basic authentication method. If you select this method, you must specify the username and password that are used for authentication.

        • OAuth Client Credential: the OAuth authentication method. This method is more secure and reliable than other methods.

        • API Key: a simple authentication method. If you select this method, you must specify the name and value of the API key.

        Network

        Internet

        The network type. Valid values:

      5. (Optional). In the Retry Policy and Dead-letter Queue section, 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 left-side navigation pane, click Event Buses.

  2. In the top navigation bar, select a region.
  3. On the Event Buses page, find the custom event bus that you want to manage and click Publish Event in the Operations column.

    Note

    You can publish events only to custom event buses in the EventBridge console.

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

    Note
    • For information about the event parameters, see Overview.

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

Verify the result

  1. Go to the Overview page of the event bus that you want to manage.

  2. In the left-side navigation pane, click Event Tracking. Then, click the Query By Event ID tab.

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

  4. In the Operations column of the queried event, click Event Trace to check whether the event is delivered.

    UYyMHxrJvw