serverless: Can't create two lambdas using the same eventBus
Bug Report
Description
Create two lambda functions using the same eventBus on EventBridge service gives an error that eventBus cannot be created.
-
What did you do? Try to create two lambda functions using the same event bus
-
What happened? Gives an error failed to create resource already exists
-
What should’ve happened? Create the two lambdas using the same eventBus
-
What’s the content of your
serverless.ymlfile?
service: my-service
provider:
name: aws
stage: ${opt:stage}
runtime: go1.x
region: us-east-1
package:
exclude:
stage: ${opt:stage}
- ./**
include:
- ./bin/**
functions:
plans-create:
handler: bin/eventbridge/plans/create
events:
- eventBridge:
eventBus: mybus-${opt:stage}
pattern:
source:
- prod.admin.plans
detail-type:
- plan-created
plans-update:
handler: bin/eventbridge/plans/update
events:
- eventBridge:
eventBus: mybus-${opt:stage}
pattern:
source:
- prod.admin.plans
detail-type:
- plan-updated
Failed to create resource. Event bus mybus-dev already exists.
Similar or dependent issues:
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 20 (3 by maintainers)
Ok find a way to workaround this, like the following example, but it needs at least the
arn:awsto work@TreeMan360 Got the same
EventBus.startsWith is not a functionerror with:The event bus is being created fine when using resources, but I can’t reference with
GetAtt.So far I’m having 2 issues:
!GetAttnorFn::GetAtt.I can work this around with the custom attribute hardcoding the ARN as Eduardo did in this thread, but would be good to do it in more declarative way rather than hardcoding ARN’s.
@XM37 I have some work in progress that should address this attached to #7063. I have have had to pause on finishing/testing it at the moment though.
I know this framework is “free”, but I would have thought having 2 Lambdas on the same Event Bus was a very common use-case (and test case). Building an event bus for a single subscriber would be the edge-case here. Unfortunately I don’t have the knowledge to create a PR to fix this issue. But I sure would appreciate it - as would most people that use EventBridge - if this issue could be addressed. Thanks 🙏 .
This is still an ongoing issue. Using the workaround from @eduardonunesp got us unblocked.\
I use EventBridge extensively using Serverless and have been for some time and I don’t have any issues as long as I put the EventBridge definition in another stack.
I create an infrastructure stack (infrastructure.yml) and then I reference the Event Bus Name and Arn as outputs of that stack. Then the bus already exists and I have no issues.
In reality most of my projects have several serverless stacks so having an infrastructure stack normally becomes necessary for me at some point anyway. And I prefer it like this.
There is definitely an issue using EB in a single stack. I tried it again a couple of weeks ago and it does not work properly. So yes it should be addressed, but for now just split your stacks and everything will be awesome 🤩.
I did elude to this ages ago above. I hope this helps someone.