Anyone have any idea why `EventBus` I’ve created f...
# help
d
Anyone have any idea why
EventBus
I’ve created for
aws:mediaconvert
only triggers manually when testing but when I
mediaconvert.createJob
it successfully completes but the eventBus function doesn’t trigger. Are they any special permissions I need to add to allow mediaconvert to create that event?
Copy code
new sst.EventBus(this, 'TranscoderBus', {
      rules: {
        rule1: {
          eventPattern: {
            source: ['aws.mediaconvert'],
            detailType: ['MediaConvert Job State Change'],
            detail: {
              status: ['COMPLETE'],
            },
          },
          targets: ['lib/constructs/VideoTranscoder/lambdas/jobstatus.handler'],
        },
      },
    })
I’ve also tried lowering the eventPattern to just the source
@Frank @thdxr Just realized the issue. Perhaps the sst docs are misleading for EventBus. They all show setting the event pattern source to an aws service eg.
aws:codebuild
However, after much playing around and a support ticket to AWS, I found out that aws service events only trigger on the default bus and not custom buses. Only way to get them on the custom bus is to setup a rule on the default and target the custom bus. So I guess what I really wanted here was just a cdk core
Rule
😞
Just thinking…. this construct might be more flexible if called…
EventRule
and it allowed you to create a custom bus OR by default use the default bus. Otherwise, for default bus things… I would use this syntax…
Copy code
const jobstatusFunction = new sst.Function(this, 'JobStatusFunction', {
      handler: 'lib/constructs/VideoTranscoder/lambdas/jobstatus.handler',
    })
    new eb.Rule(this, 'TranscoderEventRule', {
      eventPattern: {
        source: ['aws.mediaconvert'],
        detailType: ['MediaConvert Job State Change'],
        detail: {
          status: ['COMPLETE'],
        },
      },
      targets: [new ebt.LambdaFunction(jobstatusFunction)],
    })
a
why just not import the existing default EventBus as described here - https://docs.serverless-stack.com/constructs/EventBus#importing-an-existing-eventbus ? Also, in the long run having an application specific event bus makes a lot of sense. I’d listen to the events from the default EventBus and transform and publish it to my application specific bus. This is an overkill for most applications but since I’m working on implementing Event Sourcing it makes sense to me.
t
Agreed
d
fair enough, never thought to pull in the default eventBus. Still think the docs could use a small call out that in order for the simple example to work.. you would have to setup another Rule to push events to custom bus.
f
Ah good point, the docs should make this clear
Just updated the doc and added “Receiving AWS events” example https://docs.serverless-stack.com/constructs/EventBus#receiving-aws-events
j
Just an observation, you may find it easier to standardize your detailType format e.g. resource.subresource.effect. Instead of ‘MediaConvert Job State Change’ something like ‘media_conversion.completed’, ‘media_conversion.started’, etc. This is easier to parse, predict and reason about across different teams as you scale. You may find Stripe’s example beneficial: https://stripe.com/docs/api/events/types