Stacktape
Stacktape


Event Buses



An event bus allows you to build scalable, event-driven applications. It's a serverless service that automatically scales based on the number of events ingested, and you only pay for the events you publish. Events can be published from your own applications or from third-party SaaS applications.

Under the hood, Stacktape uses Amazon EventBridge.

When to use them

Stacktape offers three managed resources for messaging and communication:

  1. SNS topics
  2. SQS queues
  3. Event buses

Use an SNS topic when:

  • You need to publish messages to many different subscribers with a single action.
  • You require high throughput and reliability.

Use an SQS queue when:

  • You need reliable, one-to-one, asynchronous communication to decouple your applications.
  • You want to control the rate at which messages are consumed.

Use an event bus when:

  • You want to publish messages to many subscribers and use the event data itself to filter which messages are delivered to which subscribers.
  • You need to integrate with third-party SaaS providers like Shopify, Datadog, or PagerDuty.

Basic usage

EventBus  API reference
type
Required
properties.eventSourceName
properties.archivation
overrides

You don't need to specify any properties to create a basic event bus.

resources:
myEventBus:
type: 'event-bus'

Integrating with compute resources

Events published to an event bus can trigger a batch job or a function. Events can be published from any compute resource with the necessary permissions.

This example shows:

  • An event bus that acts as a bridge between a publisher function and a consumer batch job.
  • An HTTP API Gateway that triggers the publisher function.
  • A publisher function that receives requests from the API Gateway and publishes a BUDGET_ANALYSIS event to the event bus.
  • A consumer batch job that is triggered by the BUDGET_ANALYSIS event.
variables:
eventName: 'BUDGET_ANALYSIS'
resources:
myEventBus:
type: 'event-bus'
myPublisherFunction:
type: 'function'
properties:
packaging:
type: stacktape-lambda-buildpack
properties:
entryfilePath: '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
connectTo:
- myEventBus
events:
- type: http-api-gateway
properties:
httpApiGatewayName: 'myHttpApi'
method: 'GET'
path: '/budget-analysis'
myConsumerBatchJob:
type: batch-job
properties:
container:
packaging:
type: stacktape-image-buildpack
properties:
entryfilePath: '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'

Archiving

Event buses support event archiving. You can replay an archive at any time, which is useful for recovering from errors or for testing.

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

Referenceable parameters

The following parameters can be easily referenced using $ResourceParam directive directive.

To learn more about referencing parameters, refer to referencing parameters.

arn
  • Arn of the event bus

  • Usage: $ResourceParam('<<resource-name>>', 'arn')
archiveArn
  • Arn of the event bus archive (available only if the archivation is enabled)

  • Usage: $ResourceParam('<<resource-name>>', 'archiveArn')

Contents