logoStacktape docs




Event Buses

Overview and basic concepts

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.

When to use

Event buses make it easier to connect applications. In Stacktape, you can seamlessly integrate a batch-job or a function with event bus, which gives enables triggering them as a reaction to published events.

Advantages

  • Pay-per-use - You are NOT paying for event-bus being deployed. You are only paying for the events published to the event-bus. AWS charges $1.00 per million events published.
  • Scaling - Event buses are able to digest thousands of events per second. Exact limits differ based on the region and can be found in AWS docs. Most of these limits are soft and can be increased. There are virtually almost no limits.
  • Security - Event buses are robustly secured by default. Events can be published from your functions, batch-jobs or container-workloads.
  • Integrating with workloads - Thanks to event-bus integration, you can easily trigger your function or batchJob as a reaction to specific event.

Basic usage

EventBus  API reference
type
Required

No description

Type: string "event-bus"

properties.eventSourceName

Specifies the partner event source that the new event bus will be matched with.

Type: string

  • Required only if you are using a partner event bus (3rd party)

overrides

Overrides one or more properties of the specified child resource.

Type: Object

  • Child resouces are specified using their descriptive name (e.g. DbInstance or Events.0.HttpApiRoute).
  • To see all configurable child resources for given Stacktape resource, use stacktape stack-info --detailed command.
  • To see the list of properties that can be overriden, refer to AWS Cloudformation docs.

No properties need to be specified when creating event-bus.

resources:
myEventBus:
type: 'event-bus'

Integrating with workloads

Events published into event-bus can easily trigger:

Events can be published from any workload: function, batch-job or 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_ANALISYS event to myEventBus
  • myConsumerBatchJob - batch-job, which is integrated with myEventBus and is triggered by BUDGET_ANALISYS event (published by myPublisherFunction)

variables:
eventName: 'BUDGET_ANALYSIS'
resources:
myEventBus:
type: 'event-bus'
myPublisherFunction:
type: 'function'
properties:
packageConfig:
filePath: 'lambdas/event-bus-publisher.ts'
environment:
- name: EVENT_NAME
value: $Var().eventName
- name: EVENT_BUS_NAME
value: "$Param('myEventBus', 'EventBus::Name')"
# granting access for function to publish events into myEventBus
accessControl:
allowAccessTo:
- 'myEventBus'
events:
- type: http-api-gateway
properties:
httpApiGatewayName: 'myHttpApi'
method: 'GET'
path: '/budget-analysis'
myConsumerBatchJob:
type: batch-job
properties:
container:
imageConfig:
filePath: 'batch-jobs/event-bus-consumer'
resources:
cpu: 1
memory: 200
# batch-job is triggered if myEventBus receives event that matches the specified eventPattern
events:
- type: event-bus
properties:
eventBusName: myEventBus
eventPattern:
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.

resources:
myBus:
type: event-bus
properties:
archivation:
enabled: true

EventBusArchivation  API reference
Parent API reference: EventBus
enabled
Required

Enables event archivation

Type: boolean

  • Disabling of archive results in deletion of the archive

retentionDays

Configures retention period for events in this event bus

Type: number

  • By default event are retained indefinitely