All Products
Search
Document Center

Container Compute Service:Use the event-driven capabilities of EventBridge in Knative

Last Updated:Mar 26, 2026

Trigger the Knative service through EventBridge

Knative Eventing provides an event model that simplifies ingesting events from external systems. Events flow through the cluster in the standard CloudEvents format. This tutorial shows how to use EventBridge as an event source and trigger a Knative service to process those events.

By the end of this tutorial, you will have a working pipeline where uploading an object to an Object Storage Service (OSS) bucket triggers EventBridge, which delivers the event to a Knative service for processing.

Steps in this tutorial:

  1. Deploy the Eventing and EventBridge components

  2. Create a Knative service

  3. Create a trigger

  4. Verify the event pipeline

Prerequisites

Before you begin, ensure that you have:

EventBridge is a serverless event bus service that routes events between Alibaba Cloud services, custom applications, and software-as-a-service (SaaS) applications based on the CloudEvents 1.0 specification.

How it works

EventBridge supports a wide range of event sources. Configure an event bus, rules, and targets to filter, transform, and deliver events to a Knative service. The Knative service scales up on demand to process each event and scales back to zero when idle.

image
You can use OSS as an event source for EventBridge. For details, see OSS events.

Step 1: Deploy the Eventing and EventBridge components

Deploy Eventing first, then deploy EventBridge. Both components are required for Knative to support Alibaba Cloud event sources and event forwarding.

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the ID of the target cluster. In the left-side navigation pane, choose Applications > Knative.

  3. On the Components tab, deploy the two components in order:

    1. Find Eventing and click Deploy in the Actions column.

    2. After Eventing is deployed, find EventBridge and click Deploy in the Actions column. In the dialog box, enter your AccessKey ID and AccessKey secret, then click OK. To get an AccessKey pair, see Create an AccessKey. > Note: Bind a multi-factor authentication (MFA) device to the RAM user to add a second layer of protection for console logon and sensitive operations. For details, see Bind an MFA device to a RAM user.

Result: When Deployed appears in the Status column for both components, the components are ready.

Step 2: Create a Knative service

This step creates an event-display Knative service that automatically logs all received events. Choose either the ACS console or kubectl.

Use the ACS console

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the ID of the target cluster. In the left-side navigation pane, choose Applications > Knative.

  3. Click the Services tab, then click Create from Template.

  4. Paste the following YAML and submit:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: event-display
      namespace: default
    spec:
      template:
        spec:
          containers:
          - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/event-display:20230207194118_3874dbd

Result: When Created appears in the Status column for event-display on the Services tab, the Knative service is ready.

Use kubectl

  1. Create event-display.yaml with the following content:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: event-display
      namespace: default
    spec:
      template:
        spec:
          containers:
          - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/event-display:20230207194118_3874dbd
  2. Apply the manifest:

    kubectl apply -f event-display.yaml
  3. Verify the Knative service is ready:

    kubectl get ksvc

    Expected output:

    NAME            URL                                        LATESTCREATED         LATESTREADY           READY   REASON
    event-display   http://event-display.default.example.com   event-display-00001   event-display-00001   True

    READY: True confirms the Knative service is running.

Step 3: Create a trigger

A trigger subscribes to events from a broker and forwards matching events to a Knative service. Configure the broker, event source, and event type to control which events reach your service.

Use the ACS console

  1. On the Knative page, click the Services tab, then click the name of the Knative service. On the details page, click the Trigger tab.

  2. Click Create Trigger. On the Configure page, set the following parameters:

    Parameter Description Example
    Name Name for the trigger my-service-trigger
    Broker Select EventBridge or Other EventBridge
    Event Source The source service that emits events OSS
    Event Type The event type to filter on; separate multiple types with commas oss:ActionTrail:ConsoleOperation

Result: After the trigger is created, it appears on the Triggers tab.

image

Use kubectl

  1. Create my-service-trigger.yaml with the following content:

    Field Description
    broker Set to eventbridge-default-broker, which maps to the default event bus
    source The event source supported by EventBridge (for example, acs.oss)
    type The event type from that source; separate multiple types with commas
    subscriber The Knative service that receives matching events
    apiVersion: eventing.knative.dev/v1
    kind: Trigger
    metadata:
      name: my-service-trigger
    spec:
      broker: eventbridge-default-broker
      filter:
        attributes:
          source: acs.oss
          type: 'oss:ActionTrail:ConsoleOperation'
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: helloworld-go
          namespace: default

    Key fields:

  2. Apply the manifest:

    kubectl apply -f my-service-trigger.yaml
  3. Verify the trigger is ready:

    kubectl get triggers

    Expected output:

    NAME                         BROKER                       SUBSCRIBER_URI                                   AGE   READY   REASON
    my-service-trigger           eventbridge-default-broker   http://helloworld-go.default.svc.cluster.local   42h   True

    READY: True confirms the trigger is active and listening for events.

Step 4: Verify the event pipeline

Upload an object to OSS to confirm the full pipeline works end to end.

Important

The OSS bucket and EventBridge must be in the same region.

Trigger an event

Upload an object to OSS using ossutil:

ossutil cp <file-name> oss://<bucket-name>

Replace <file-name> with the local file path and <bucket-name> with your OSS bucket name. After the upload completes, EventBridge detects the OSS event and delivers it to the Knative service through the trigger.

Check the event trace in EventBridge

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

  2. On the Event Buses page, click Event Tracking in the Actions column for the default event bus.

  3. On the Query By Time Range tab, set the Time Range to cover the upload time, then click Query.

  4. Set Event Source to OSS and Event Type to Put Object. In the Operations column for the matching event, click Event Trace. The Event Trace page shows whether the event was delivered successfully through the pipeline.

    image.png

Confirm the Knative service processed the event

  1. Check that the event-display pod is running:

    kubectl get pod

    Expected output:

    NAME                                              READY   STATUS    RESTARTS   AGE
    event-display-00001-deployment-56cc79****-z2vhv   2/2     Running   0          7s

    The pod started in response to the incoming event, which confirms the trigger fired correctly.

  2. View the event payload logged by the service:

    kubectl logs event-display-00001-deployment-56cc79****-z2vhv user-container

    Expected output:

    {"data":{"eventVersion":"1.0","responseElements":{"requestId":"63E21F5FEE852133319101AD"},"eventSource":"acs:oss","eventTime":"2023-02-07T09:52:31.000Z","requestParameters":{"sourceIPAddress":"XX.XXX.XX.XXX"},"eventName":"ObjectCreated:PutObject","userIdentity":{"principalId":"1118324452360952"},"region":"cn-hangzhou","oss":{"bucket":{"name":"knative","arn":"acs:oss:cn-hangzhou:1581204543170042:knative","virtualBucket":"","ownerIdentity":"1581204543170042"},"ossSchemaVersion":"1.0","object":{"size":225496,"objectMeta":{"mimeType":"application/octet-stream"},"deltaSize":0,"eTag":"B350C082843DAC7E9E634193437EBA30","key":"demo.data"}}}}

    The eventName: ObjectCreated:PutObject field confirms that the Knative service received and logged the OSS upload event. EventBridge successfully delivered the event through the trigger pipeline.

What's next

To set up event-driven workflows with other event sources, see Use GitHub events in Knative.