Using EventBridge with IaC


As the infrastructure for building an EDA architecture, EventBridge provides flexible and rich capabilities for event collection, processing, and routing through some core concepts and features. For many users, using EventBridge through convenient guidance on the console should be the fastest way to get started. In addition, many users are also facing the management of a large number of cloud products, and using the console to manage each resource has become a heavy manual operation burden.

To address this issue, it is now possible to quickly and conveniently bring the capabilities of EventBridge to users through methods such as OpenAPI and Terraform. This article will focus on the key concepts and features of EventBridge and IaC, and then demonstrate how to apply the IaC concept to automate the deployment of EventBridge to use these concepts and features.

Overview of EventBridge

Event Driven Architecture

Event driven architecture is a loosely coupled and distributed driver architecture that collects events generated by an application and takes necessary processing in real-time, followed by routing to downstream systems without waiting for system responses. Using the Event Bus EventBridge, various simple or complex event driven architectures can be constructed to connect cloud products and applications, applications and applications, etc. using standardized CloudEvents 1.0 protocol.

The event driven architecture architecture has the following three capabilities:

Event Collection: Responsible for collecting events related to various applications, such as new orders, return and exchange orders, and other status changes;

Event handling: Desensitize the event and conduct preliminary filtering and screening of the event;

Event routing: Analyze event content and distribute event routing to downstream products.

Event driven architecture has the following advantages:

• Reduce coupling: reduce the coupling between event producers and subscribers. Event producers only need to pay attention to the occurrence of the event, without paying attention to how the event is handled or to which subscribers it is distributed; If any link malfunctions, it will not affect the normal operation of other businesses;

Asynchronous execution: Event driven architecture is suitable for asynchronous scenarios, even during peak demand periods, collecting events from various sources and retaining them in the event bus, and then gradually distributing and delivering events, without causing system congestion or resource surplus;

• Scalability: In event driven architecture, routing and filtering capabilities support the division of services, facilitating expansion and routing distribution;

Agility: The event driven architecture supports integration with various Alibaba Cloud products and applications, supports event routing to any system service, and provides various agile and efficient deployment solutions.

Building an EDA architecture using EventBridge

EventBridge is a serverless event bus service provided by Alibaba Cloud. The several core concepts provided by EventBridge can meet the needs of building an EDA architecture.

The Event Bus EventBridge supports the following event sources:

Alibaba Cloud official event source

• Custom event sources

The event bus of EventBridge includes the following types:

Cloud Service Dedicated Event Bus: A built-in event bus that does not need to be created and cannot be modified, used to receive events from your Alibaba Cloud official event source; The official event source of Alibaba Cloud can only publish events to the cloud service dedicated bus;

• Custom event bus: an event bus that you need to create and manage yourself to receive events from custom applications or stock message data; Events for custom applications or stock message data can only be published to custom buses.

In EventBridge, an event rule contains the following content:

Event mode: used to filter events and route them to event targets;

Event objectives: including event transformation and processing, responsible for consuming events.

EventBridge provides concise event pattern matching syntax and flexible event conversion capabilities. Specific examples will be demonstrated later.

In addition, EventBridge also provides some enhanced capabilities that make the events flowing through the EDA architecture more transparent, providing out of the box observation and analysis capabilities:

Event tracking: You can view the event content and processing trajectory published to the event bus EventBridge;

• Event analysis: query, analyze, process and visualize various events published to the event bus, so as to discover the intrinsic value of events.

IaC Introduction

After introducing the basic content of the Event Bus EventBridge, let's take a look at IaC together. In the practice of DevOps, IaC is a very important part. By coding and versioning the infrastructure, version control tools can be easily used to provide a single source of truth, coordinate changes for multi-party collaboration, implement strict reviews, and trigger deployment through some CI/CD pipeline tools (even GitOps). Developers of software systems can obtain the required cloud services such as virtual machines and networks with minimal effort to describe requirements in just a few minutes, greatly reducing deployment time and ensuring consistency in configuration across multiple environments. By reducing human operations, the probability of introducing errors is also reduced.

There are generally two ways to code IaC in practice, imperative and declarative.

Command based: As the name suggests, it is necessary to clearly issue instructions for each action, describing how, such as "creating an ECS with xx specifications". The code needs to carefully arrange the order of each action step, handle various possible errors, and pay particular attention to handling the impact of each change on existing resources, otherwise a slight mistake may cause service interruption. For example, as a developer, you can use familiar programming languages to call Alibaba Cloud's OpenAPI to manage resources, as these APIs perform operations such as Create, Describe, Delete, etc. This is a command-based IaC practice.

• Explicit: This means that developers only describe what their requirements will look like, such as "an ECS with xx specifications". Students who are familiar with Kubernetes should be very familiar with this concept. IaC tools can automatically arrange the order by describing the dependency relationships between resources. If there are existing resources, they compare the differences between the expected and actual states and make updates based on the differences; If it does not exist, it needs to be created. It can be seen that declarative language is very friendly to developers, greatly reducing their mental burden.

Advantages brought by IaC:

• Cost reduction: Effectively manage resources and reduce the amount of manpower invested for this purpose;

• Improve efficiency: accelerate resource delivery and software deployment;

Risk control:

• Reduce errors;

• Improve infrastructure consistency;

• Eliminate configuration offsets

Terraform, as a leader in the IaC field, provides powerful automated management infrastructure capabilities. Rich ecosystem, many cloud manufacturers have provided official plugins, and most of Alibaba Cloud's products (including EventBridge) provide comprehensive support for Terraform, making it extremely easy to deploy infrastructure across multiple clouds. Since it is IaC, Terraform provides its own language HCL (hashicorp configuration language), which has a concise syntax similar to JSON. By using declarative resource descriptions, developers can quickly get started.

Hands-on practice


Install the Terraform cli tool, which can be found in the The content of.

Create a tf file with the following content (values in<>need to be replaced)

provider "alicloud" {

access_ key = ""

secret_ key = ""

region = ""


Case 1: Monitoring changes in cloud resources through DingTalk

Assuming a user uses many cloud resources as a production environment and needs to perceive changes in online resources, a feasible solution is to use EventBridge to post audit events from ActionTrail to the user's nails.

Firstly, create a robot based on the official document of DingTalk, note down the webhook URL and the signature key, which will be used later.

Create a tf file 1_, the content is as follows (the value in<>needs to be replaced)

Execute commands in sequence in the command line window:

• Initialize terraform init

• Preview the change terraform plan

• Apply terraform changes

Operate on the cloud product console, using KMS as an example

Received message notification on the nail

Viewing Event Trajectories in the EventBridge Console

Case 2: Custom Bus Triggering FunctionCompute

Assuming a user's application generates some events, one of which is processed elastically through FunctionCompute. So, this solution can be achieved by using the custom event source and function of EventBridge to calculate the event target.

Create a Python script file src/ that simulates the processing of events, with the following content:

Execute commands sequentially in the command line window

• Initialize terraform init

• Preview the change terraform plan

• Apply terraform changes

Simulate custom event sources and publish events on the console

View function call logs on the console page of FunctionCompute

Viewing Event Trajectories in the EventBridge Console


As the infrastructure for building an EDA architecture, EventBridge provides flexible and rich event collection, processing, and routing capabilities through some core concepts and features, and supports bringing these capabilities to users conveniently and quickly through methods such as OpenAPI and Terraform. This article introduces the key concepts and features of EventBridge and IaC, and then demonstrates how to apply the IaC concept to automate the deployment of EventBridge to use these concepts and features.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us