EventBus
A custom EventBridge event bus with pattern-matching rules that route events to Lambda functions or SQS queues.
Minimal
The smallest config that deploys.
import { App } from '@anvil-cloud/sdk';
import * as anvil from '@anvil-cloud/sdk';
export default new App({
run(ctx) {
const orders = new anvil.aws.EventBus('orders');
},
});import anvil_cloud as anvil
def infra(ctx: anvil.Context):
orders = anvil.aws.EventBus("orders")
anvil.App(run=infra)package main
import (
"github.com/anvil-cloud/anvil/sdk/go/anvil"
anvilaws "github.com/anvil-cloud/anvil/sdk/go/anvil/aws"
)
func main() {
anvil.Run(anvil.AppConfig{
Run: func(ctx *anvil.Context) error {
_, err := anvilaws.NewEventBus(ctx.PulumiCtx(), "orders", nil)
if err != nil {
return err
}
return nil
},
})
}Granting access
Let compute publish with grantPutEvents. Rules route matching events to a Lambda, and Anvil adds the permission that lets the rule invoke it.
orders.grantPutEvents(api);orders.grant_put_events(api)// Go has no grant methods yet: give the Lambda the same actions with permissions.
api, err := anvilaws.NewLambda(ctx.PulumiCtx(), "api", &anvilaws.LambdaArgs{
Runtime: anvilaws.LambdaRuntime_Nodejs24_x,
Handler: pulumi.String("functions/api/index.handler"),
Permissions: anvilaws.LambdaPermissionArray{
anvilaws.LambdaPermissionArgs{
Actions: pulumi.ToStringArray([]string{"events:PutEvents"}),
Resource: orders.Arn,
},
},
})
if err != nil {
return err
}What Anvil creates
grantPutEventsaddsevents:PutEventson this bus only, so the compute can publish here and nowhere else.- Each rule's target Lambda gets a resource permission letting only that rule invoke it.
- It's an inline policy on the compute's role, removed when you remove the grant.
Good to know
- Publish to this bus by name (the
nameoutput), not the account's default bus. - A rule's
patternmatches onsource,detailTypeanddetail. Events that match no rule are dropped.
The Full example tab has a complete program. Every argument and attribute is on the Reference tab.