Event Buses
Overview
Event bus makes it easier to build event-driven applications at scale. An event bus is fully serverless. There are no servers to provision, patch, and manage. It automatically scales based on the number of events ingested, and you pay only for events published into your event bus. Events can be published from your custom apps. It is also possible for event bus to receive events from SaaS partner applications and services.
Under the hood
Event bus is an abstraction for Amazon EventBridge service.
When to use
Stacktape offers 3 types of AWS managed resources intended for messaging/communication(all use "pay per use" model and scale automatically):
Depending on you use case you might choose to use:
Use SNS topic when
- You want to publish messages to MANY different subscribers with a single action.
- Require high throughput and reliability for publishing and delivery to consumers.
- Have many subscribers.
Use SQS queue when
- You are looking for reliable 1:1 asynchronous communication to decouple your applications from one another
- You want to rate limit your consumption of messages (in case of SQS consumer fetches the messages so you can control the rate)
Use Event bus when
- You want to publish messages to many subscribers, and use the event data itself to match targets interested certain patterns (with even bus, you can filter which messages should be delivered to the subscriber based on message content)
- You want integration with other SaaS providers such as Shopify, Datadog, Pagerduty, or others.
Basic usage
No properties need to be specified when creating event-bus.
Copy
resources:myEventBus:type: 'event-bus'
Integrating with compute resources
Events published into event-bus can easily trigger:
- batch-job - see integration
- function - see integration
Events can be published from any workload: function, batch-job or multi-container-workloads with sufficient rights granted.
Following example shows:
- myEventBus - event-bus, which is used as a bridge between myPublisherFunction and myConsumerBatchJob
- myHttpApi - http-api-gateway, which is integrated with and triggers myPublisherFunction
- myPublisherFunction - function, which receives events (requests) from myHttpApi and decides whether to publish BUDGET_ANALYSIS event to myEventBus
- myConsumerBatchJob - batch-job, which is integrated with myEventBus and is triggered by BUDGET_ANALYSIS event (published by myPublisherFunction)
Copy
variables:eventName: 'BUDGET_ANALYSIS'resources:myEventBus:type: 'event-bus'myPublisherFunction:type: 'function'properties:packaging:type: stacktape-lambda-buildpackproperties:entryfilePath: 'lambdas/event-bus-publisher.ts'environment:- name: EVENT_NAMEvalue: $Var().eventName- name: EVENT_BUS_NAMEvalue: $Param('myEventBus', 'EventBus::Name')# granting access for function to publish events into myEventBusconnectTo:- myEventBusevents:- type: http-api-gatewayproperties:httpApiGatewayName: 'myHttpApi'method: 'GET'path: '/budget-analysis'myConsumerBatchJob:type: batch-jobproperties:container:packaging:type: stacktape-image-buildpackproperties:entryfilePath: 'batch-jobs/event-bus-consumer'resources:cpu: 1memory: 200# batch-job is triggered if myEventBus receives event that matches the specified eventPatternevents:- type: event-busproperties:eventBusName: myEventBuseventPattern:detail:EventName:- '$Var().eventName'myHttpApi:type: 'http-api-gateway'
Archivation
- Event buses support event archiving.
- The archive can be at any time replayed into the event-bus.
- This can be helpful when a problem occurs in the system and you want to replay events after the problem is fixed.
Copy
resources:myBus:type: event-busproperties:archivation:enabled: true
Referenceable parameters
The following parameters can be easily referenced using $ResourceParam directive directive.
To learn more about referencing parameters, refer to referencing parameters.
Arn of the event bus
- Usage:
$ResourceParam('<<resource-name>>', 'arn')
Arn of the event bus archive (available only if the archivation is enabled)
- Usage:
$ResourceParam('<<resource-name>>', 'archiveArn')