Fix events target for custom event bus (#4168)

This commit is contained in:
Anton Grübel 2021-08-12 14:02:16 +09:00 committed by GitHub
parent f2b8318211
commit a5eb46962d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class Rule(CloudFormationModel):
def send_to_targets(self, event_bus_name, event):
event_bus_name = event_bus_name.split("/")[-1]
if event_bus_name != self.event_bus_name:
if event_bus_name != self.event_bus_name.split("/")[-1]:
return
if not self.event_pattern.matches_event(event):

View File

@ -206,3 +206,48 @@ def test_send_to_sqs_queue():
body["region"].should.equal("eu-central-1")
body["resources"].should.be.empty
body["detail"].should.equal({"key": "value"})
@mock_events
@mock_sqs
def test_send_to_sqs_queue_with_custom_event_bus():
# given
client_events = boto3.client("events", "eu-central-1")
client_sqs = boto3.client("sqs", region_name="eu-central-1")
event_bus_arn = client_events.create_event_bus(Name="mock")["EventBusArn"]
rule_name = "test-rule"
queue_url = client_sqs.create_queue(QueueName="test-queue")["QueueUrl"]
queue_arn = client_sqs.get_queue_attributes(
QueueUrl=queue_url, AttributeNames=["QueueArn"]
)["Attributes"]["QueueArn"]
client_events.put_rule(
Name=rule_name,
EventPattern=json.dumps({"account": [ACCOUNT_ID]}),
State="ENABLED",
EventBusName=event_bus_arn,
)
client_events.put_targets(
Rule=rule_name,
Targets=[{"Id": "sqs", "Arn": queue_arn}],
EventBusName=event_bus_arn,
)
# when
client_events.put_events(
Entries=[
{
"Source": "source",
"DetailType": "type",
"Detail": json.dumps({"key": "value"}),
"EventBusName": event_bus_arn,
}
],
)
# then
response = client_sqs.receive_message(QueueUrl=queue_url)
assert len(response["Messages"]) == 1
body = json.loads(response["Messages"][0]["Body"])
body["detail"].should.equal({"key": "value"})