Eventbridge put_events doesn't seem to support custom event buses
See original GitHub issueSee below - message received fine for the default event bus (unspecified), but not received if one specifies a custom event bus
$ python test_moto_event_bus.py
custom bus [False] -> message received [True]
custom bus [True] -> message received [False]
from moto import mock_events, mock_sqs
from botocore.exceptions import ClientError
import boto3, copy, json, yaml
EventBase=yaml.safe_load("""
Source: my-source
DetailType: my-detail-type
""")
Statement=yaml.safe_load("""
Effect: Allow
Principal:
Service: events.amazonaws.com
Action: "sqs:SendMessage"
Resource: "*"
""")
def drain_sqs(sqs, queueurl, nmax=100):
messages, count = [], 0
while True:
resp=sqs.receive_message(QueueUrl=queueurl)
if ("Messages" not in resp or
count > nmax):
break
messages+=resp["Messages"]
count+=1
return messages
@mock_events
@mock_sqs
def test_event_pattern(custom=False,
detail={"event": {"root": "child"},
"pattern": {"root": ["child"]}},
eventbase=EventBase,
statement=Statement,
eventbusname="my-event-bus"):
events, sqs, = boto3.client("events"), boto3.client("sqs")
if custom:
events.create_event_bus(Name=eventbusname)
policy=json.dumps({"Version": "2012-10-17",
"Statement": [statement]})
queue=sqs.create_queue(QueueName="my-queue",
Attributes={"Policy": policy})
queueurl=queue["QueueUrl"]
queueattrs=sqs.get_queue_attributes(QueueUrl=queueurl)["Attributes"]
queuearn=queueattrs["QueueArn"]
pattern={"detail": detail["pattern"]}
events.put_rule(Name="my-rule",
State="ENABLED",
EventPattern=json.dumps(pattern))
events.put_targets(Rule="my-rule",
Targets=[{"Id": "my-target-id",
"Arn": queuearn}])
event=copy.deepcopy(eventbase)
event["Detail"]=json.dumps(detail["event"])
if custom:
event["EventBusName"]=eventbusname
events.put_events(Entries=[event])
return drain_sqs(sqs, queue["QueueUrl"])
if __name__=="__main__":
try:
for flag in [False, True]:
messages=test_event_pattern(custom=flag)
print ("custom bus [%s] -> message received [%s]" % (flag,
bool(len(messages))))
except ClientError as error:
print ("Error: %s" % str(error))
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Can I put custom events in the default event bus in AWS ...
Yes you can, see the first paragraph of this docs page https://docs.aws.amazon.com/eventbridge/latest/userguide/create-event-bus.html.
Read more >Sending and receiving Amazon EventBridge events between ...
You can send and receive events between event buses in AWS accounts within ... one account to another are charged to the sending...
Read more >Amazon EventBridge - Sending events to the event bus
There are multiple ways to send events to EventBridge and in this video ... to put events on event buses in your production...
Read more >How To Set Up A Custom Event Bus With Amazon EventBridge
Learn how to set up a custom event bus in Amazon EventBridge using the AWS Management Console or the AWS CLI. You can...
Read more >Eventbridge bus: can't receive messages on custom event bus?
The custom bus can only receive custom events from your application, e.g.: "source": [ "myapp.test" ]. From docs: When an AWS service in ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@bblommers you’re 100% right - sorry for the trouble but many thanks. Closed.
Hey @jhw - Moto hasn’t specifically signed up for any, and I haven’t personally used any bounty programs either.
With those caveats out of the way: Is it possible to use a generic program, like Bountysource.com? The Github-authentication seems broken at the moment, so I can’t login and verify, but as far as I know that’s a pretty generic (project independent) way of posting and resolving open source bounties.