<https://docs.serverless-stack.com/constructs/Even...
# help
f
Hey @Nathan, it’s a bit tricky to do it right now. Lemme push out an update.
I will keep you posted in an hour or so.
n
Hey Frank. Wow thanks! looking forward to it.
f
@Nathan so I just added support for reusing existing Functions as targets, (haven’t released yet):
Copy code
import * as lambda from "aws-cdk-lib/aws-lambda";

new EventBus(stack, "Bus", {
  rules: {
    rule1: {
      pattern: { source: ["myevent"] },
      targets: {
        myTarget: {
          cdk: {
            function: lambda.Function.fromFunctionName(stack, "ITarget", "my-function"),
          },
        },
      },
    },
  },
});
It works when the imported function is in the same Account/Region as the app.
Do u know if it’s possible to add a target to an EventBus that’s in another account?
n
Sorry i may have misspoke. The lambda is in another repo, different stack. I know the arn. If the function name works, that is ok because the bus is in the same account
In the cdk eventbus you can create a target with the ‘fromArn’ method and then specify which bus to assign the target to.
Let me see if the function name works
f
ah that makes sense. I will cut a release in a bit.
n
Thanks Frank! wow that is some service