Hello!
I have two separate serverless.yml projects that have to interact with an EventBridge rule and I'm struggling to figure out how to update the resources section in both to support this. Here's an example of what I mean:
EntryPoint Lambda:
This lambda gets the request from the front end and then submits a message to the EventBridge rule we have setup. The EventBridge rule is setup in the serverless.yml file like so:
resources:
Resources:
RegisterEventBridge:
Type: "AWS::Events::Rule"
Properties:
Name: "RegisterCloseEventBridge"
Description: "Event rule for Closing Register event."
State: "ENABLED"
EventPattern:
source:
- "register.close.${self:provider.stage}"
Consumer:
This lambda function gets triggered by a SQS message. The SQS is a target for the EventBridge rule so it seems like the queue itself should be created in this service. Below is the resources:
resources:
Resources:
ClosingRegisterQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: "closing-register-sqs-${self:provider.stage}"
RegisterEventBridge:
Type: "AWS::Events::Rule"
Properties:
Name: "RegisterCloseEventBridge"
EventPattern:
source:
- "register.close.${self:provider.stage}"
Targets:
- Arn: !GetAtt ClosingRegisterQueue.Arn
Id: "SA"
But obviously this does not work because the RegisterEventBridge rule already exists in the previous stack. Is there any way I can simply import it into this stack for this purpose?
Okay that makes sense. I was putting it in the Entry Point because that lambda itself submits to the EventBridge rule... So I had assumed that means that the service itself should create it. It makes it way easier to keep EventBridge and SQS inside of the single Consumer lambda. Thank you for your assistance!