chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Support for custom EventBridge event buses

Open jonathanbaynham opened this issue 3 years ago • 7 comments

Is there any plan to support more EventBridge functionality? In particular, custom event buses. If I create a chalice project and use the app.schedule or app.on_cw_event annotations, Chalice generates EventBridge rules on the default event bus. It would be even better if I could specify a customer event bus instead.

jonathanbaynham avatar Jun 14 '21 19:06 jonathanbaynham

Looks like we just need to add a new EventBusName param to support this, should be a straightforward change. Marking as a feature request.

jamesls avatar Jun 14 '21 20:06 jamesls

What is the status on this ? @jamesls

Eggwise avatar Mar 04 '22 06:03 Eggwise

I see nowhere in the docs eventbridge support aswell. I think it would be a nice feature as for now me and people like me are forced to use something else than chalice because you cant trigger on eventbridge events.

Eggwise avatar Mar 04 '22 06:03 Eggwise

....

Eggwise avatar Apr 04 '22 06:04 Eggwise

2023 and an improvement for this is not yet proposed, it would be a very interesting change

baltamar3 avatar Apr 05 '23 00:04 baltamar3

FYI if someone is looking for a workaround, since the events are so similar, I was able to get this working in a chalice CDK project, by overriding the sam template, e.g.

        res = self.chalice.sam_template.get_resource(handler)
        res.add_property_override(f"Events.{handler}Event.Type", "EventBridgeRule")
        res.add_property_override(f"Events.{handler}Event.Properties.EventBusName", event_bus)

where handler will be the camelCased name of your event function. E.g.

@app.on_cw_event(...)
def on_my_event(event):
...

then handler will be OnMyEvent.

ogrodnek avatar Sep 01 '23 19:09 ogrodnek

Equivalent when using SAM with chalice:

  HandleEvent: # Other properties are defined in chalice code
    Properties:
      Events:
        HandleEvent:
          Properties:
            EventBusName: "your-bus-name"
          Type: EventBridgeRule
# This is changed to EventBridge in sam-resources.yaml
@app.on_cw_event(
    {"source": ["your-source"], "detail-type": ["your-detail-type"]}
)
def handle_event(event):
    pass

MatthijsPiek avatar Feb 28 '24 15:02 MatthijsPiek