Search code examples
aws-event-bridgepulumi

Can't create event rule on custom event bus using Pulumi


I have the following Pulumi resources in my stack:

        ....
        var eventBus = new Aws.CloudWatch.EventBus("WebhookEventBus", new EventBusArgs()
        {
            Name = "WebhookEventBus"
        });

        var sendToApiRule = new Aws.CloudWatch.EventRule("SendToApi", new EventRuleArgs()
        {
            EventBusName = eventBus.Name,
            EventPattern = @"{
                ""source"": [{ ""prefix"": ""xxxx"" }]
            }"
        });

        var devTarget = new Aws.CloudWatch.EventTarget("DevTarget", new EventTargetArgs()
        {
            Rule = sendToApiRule.Name,
            Arn = apiDestination.Arn,
            RoleArn = apiDestinationRole.Arn
        });

When creating my Pulumi Stack, I get the error:

creating EventBridge Target (SendToApi-30d74a6-DevTarget-1b917a0): ResourceNotFoundException: Rule SendToApi-30d74a6 does not exist on EventBus default.

Indeed, CloudTrail seems to confirm this error originating from events.amazonaws.com:

    ...
    "errorCode": "InternalFailure",
    "errorMessage": "An unknown error occurred",
    "requestParameters": {
        "rule": "SendToApi-8e734a8",
        "eventBusName": "default",
        "targets": [
            {
                "id": "DevTarget-eb8e26d",
                "arn": "xxxx",
                "roleArn": "xxxx"
            }
        ]
    },
    ...

I've tried using a static string "WebhookEventBus" in EventBusName. I've also tried wrapping these events in .Apply(x => ) statements, but always receive this error. Any idea why this might be?


Solution

  • You need to specify the EventBusName property as per:

    https://www.pulumi.com/registry/packages/aws/api-docs/cloudwatch/eventtarget/#eventbusname_csharp

    Currently, it's using the "default" event bus and so can't find the rule.