Why can't you create a scheduled rule on a custom bus in EventBridge?


I'm working through a design that will start with polling a couple of source systems for data and then publishing the data onto an EventBridge. I'd like to use a custom bus to keep our traffic separate from the rest of the company, however, I hit a wall a few minutes ago.

My intention was to use a rule configured to run every 15 minutes on the custom bus with a lambda target that would query the source system and then publish events onto the bus for other rules to process. But apparently, you can only create scheduled rules on the default bus.

Can anyone explain why this limitation exists? We'd like to keep the solution serverless, so what other solutions is out there for running lambdas on a schedule?



asked 2 years ago1847 views
2 Answers

Thank you for the detailed description.

As you've already mentioned, you can only create scheduled rules using the default event bus [1]. And there's no other obvious solution to run Lambda periodically.

In my opinion, it doesn't really matter on which bus we associate with a scheduled rule, as it will not look into the bus events. In your case, it would be possible for Lambda to publish events onto the other custom bus after being triggered from the default bus.

[1] https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-create-scheduled-rule

answered 2 years ago
profile pictureAWS
reviewed 2 years ago

As Weidi correctly mentioned, even though the lambda gets triggered by a scheduler event on the default bus, the lambda can put events on any custom bus

You can take a look at this workshop https://catalog.us-east-1.prod.workshops.aws/workshops/63320e83-6abc-493d-83d8-f822584fb3cb/en-US for hands-on labs on Eventbridge.

An example of Python code that puts events in a custom event bus called Orders is available in the lab:

import boto3 client = boto3.client('events')

event_bus_name = 'Orders' source = 'com.aws.orders' detail_type = 'Order Notification' detail = '{"category":"lab-supplies","value":415,"location":"eu-west"}'

try: response = client.put_events( Entries=[ { 'Source': source, 'DetailType': detail_type, 'Detail': detail, 'EventBusName': event_bus_name } ] ) print('Event sent to the event bus ' + event_bus_name) print('EventID is ' + response['Entries'][0]['EventId']) except Exception as e: print(e)

A Javascript example from the same lab is below:

// ES6+ example import { EventBridgeClient, PutEventsCommand } from "@aws-sdk/client-eventbridge"; const client = new EventBridgeClient(); const params = { Entries: [ { Detail: { "category": "lab-supplies", "value": 415, "location": "eu-west" }, DetailType: "Order Notification", EventBusName: "Orders", Source: "com.aws.orders" } ] }; const command = new PutEventsCommand(params); const response = await client.send(command);

profile pictureAWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions