Skip to content

PutEvents

Source: src/AWS/EventBridge/PutEvents.ts

Publishes events to an EventBridge event bus (events:PutEvents).

Bind this operation to an EventBus inside a function runtime to get a callable that automatically injects the bus name into every entry. Omit the bus argument to publish to the account’s default event bus. Provide the PutEventsHttp layer on the Function to satisfy the binding.

Publish an Event from a Handler

// init — bind the bus (provide AWS.EventBridge.PutEventsHttp on the Function)
const putEvents = yield* AWS.EventBridge.PutEvents(bus);
return {
fetch: Effect.gen(function* () {
// runtime — publish an event
const result = yield* putEvents({
Entries: [
{
Source: "my.app",
DetailType: "OrderCreated",
Detail: JSON.stringify({ orderId: "123" }),
},
],
});
return HttpServerResponse.json({
failedEntryCount: result.FailedEntryCount ?? 0,
});
}),
};

Publish to the Default Event Bus

// omit the bus argument to target the account's default bus
const putEvents = yield* AWS.EventBridge.PutEvents();
yield* putEvents({
Entries: [
{
Source: "my.app",
DetailType: "Heartbeat",
Detail: JSON.stringify({ at: new Date().toISOString() }),
},
],
});