What is @aws-sdk/client-eventbridge?
@aws-sdk/client-eventbridge is a part of the AWS SDK for JavaScript, which allows developers to interact with Amazon EventBridge. EventBridge is a serverless event bus service that makes it easy to connect applications using data from your own applications, integrated Software-as-a-Service (SaaS) applications, and AWS services.
What are @aws-sdk/client-eventbridge's main functionalities?
Put Events
This feature allows you to send custom events to an EventBridge event bus. The code sample demonstrates how to create an event and send it to the default event bus.
const { EventBridgeClient, PutEventsCommand } = require("@aws-sdk/client-eventbridge");
const client = new EventBridgeClient({ region: "us-east-1" });
const params = {
Entries: [
{
Source: "com.mycompany.myapp",
DetailType: "myDetailType",
Detail: JSON.stringify({ key1: "value1", key2: "value2" }),
EventBusName: "default"
}
]
};
const run = async () => {
try {
const data = await client.send(new PutEventsCommand(params));
console.log("Success, event sent; requestID:", data);
} catch (err) {
console.error(err);
}
};
run();
Create Event Bus
This feature allows you to create a custom event bus. The code sample demonstrates how to create a new event bus named 'myCustomEventBus'.
const { EventBridgeClient, CreateEventBusCommand } = require("@aws-sdk/client-eventbridge");
const client = new EventBridgeClient({ region: "us-east-1" });
const params = {
Name: "myCustomEventBus"
};
const run = async () => {
try {
const data = await client.send(new CreateEventBusCommand(params));
console.log("Success, event bus created; ARN:", data.EventBusArn);
} catch (err) {
console.error(err);
}
};
run();
List Rules
This feature allows you to list all the rules associated with a specific event bus. The code sample demonstrates how to list rules for the default event bus.
const { EventBridgeClient, ListRulesCommand } = require("@aws-sdk/client-eventbridge");
const client = new EventBridgeClient({ region: "us-east-1" });
const params = {
EventBusName: "default"
};
const run = async () => {
try {
const data = await client.send(new ListRulesCommand(params));
console.log("Success, rules listed:", data.Rules);
} catch (err) {
console.error(err);
}
};
run();
Other packages similar to @aws-sdk/client-eventbridge
aws-sdk
The 'aws-sdk' package is the older version of the AWS SDK for JavaScript. It provides similar functionalities for interacting with AWS services, including EventBridge. However, '@aws-sdk/client-eventbridge' is part of the modular AWS SDK v3, which offers better performance and smaller bundle sizes.
serverless
The 'serverless' framework allows you to build and deploy serverless applications on AWS and other cloud providers. It provides plugins and integrations for working with AWS EventBridge, making it easier to manage event-driven architectures. However, it is more of a deployment and management tool rather than a direct SDK for interacting with EventBridge.
aws-cdk
The 'aws-cdk' (AWS Cloud Development Kit) allows you to define cloud infrastructure using code and provides constructs for AWS services, including EventBridge. It is more focused on infrastructure as code (IaC) and is used for defining and provisioning AWS resources, whereas '@aws-sdk/client-eventbridge' is used for interacting with EventBridge at runtime.