question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't create two lambdas using the same eventBus

See original GitHub issue

Bug Report

Description

Create two lambda functions using the same eventBus on EventBridge service gives an error that eventBus cannot be created.

  1. What did you do? Try to create two lambda functions using the same event bus

  2. What happened? Gives an error failed to create resource already exists

  3. What should’ve happened? Create the two lambdas using the same eventBus

  4. What’s the content of your serverless.yml file?

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:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
eduardonunespcommented, Oct 25, 2019

Ok find a way to workaround this, like the following example, but it needs at least the arn:aws to work

custom:
  accountNumber: 123456789
  eventBus: arn:aws:events:us-east-1:${self:custom.accountNumber}:event-bus/mybus-${opt:stage}

functions:
  plans-create:
    handler: bin/eventbridge/plans/create
    events:
      - eventBridge:
          eventBus: ${self:custom.eventBus}
          pattern:
            source:
            - prod.admin.plans
            detail-type:
            - plan-created

resources:
  Resources:
    EventBridgeBus:
      Type: AWS::Events::EventBus
      Properties:
          Name: mybus-${opt:stage}
4reactions
michalormancommented, Feb 1, 2020

@TreeMan360 Got the same EventBus.startsWith is not a function error with:

    events:
      - eventBridge:
          eventBus:
            Fn::GetAtt: [EventBus, Arn]

The event bus is being created fine when using resources, but I can’t reference with GetAtt.

So far I’m having 2 issues:

  1. Creating 2 lambdas using same eventBus with a custom name (according to serverless documentation it automatically creates event bus in such case) raises Cloud Formation error that EventBus is already created.
  2. Creating custom eventBus in resources section I can’t reference it with !GetAtt nor Fn::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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to set multiple eventbridge rules on a lambda?
Yes, It is possible with a little workaround. Create rules as resources. Add your lambda as target to the created rules. Note: Make...
Read more >
Is it possible to set multiple eventbridge rules on a lambda?
Yes, It is possible with a little workaround. Create rules as resources. Add your lambda as ...
Read more >
Tutorial: Schedule AWS Lambda functions using EventBridge
Enter a name and description for the rule. A rule can't have the same name as another rule in the same Region and...
Read more >
Receiving events using Amazon Lambda function URLs
You can also create an event bus by selecting New event bus. Under Step 2: Set up using CloudFormation, choose New GitHub webhook....
Read more >
How To Put Event Data On AWS Event Bus Using Lambda?
Both EventBridge and SQS provide messaging patterns for your serverless setup whether it is simple messaging or pub/sub. What Is AWS EventBridge? AWS ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found