Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(cloudformation): normalize EventBridge rule bus ARN references (#2161)

Matúš Čongrády97c7fadca03d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c22be07..30350d0c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **CloudFormation — `AWS::Logs::LogGroup` delete** — a stack delete or a `LogGroupName` replacement removed only the group record, so a metric filter or resource policy added through the Logs API stayed and came back with a new group of the same name; the group is now deleted through `DeleteLogGroup`. Contributed by @iot-rocket.
- **Cognito Identity — `GetOpenIdToken` claims** — the token was a user-pool ID token with an empty audience; it is now issued by `https://cognito-identity.amazonaws.com` with the identity pool id as `aud`, the identity id as `sub`, an `amr` list naming the login providers and the user-pool sign-in, the pool ARN in `https://cognito-identity.amazonaws.com/identity-pool-arn` and a 10-minute lifetime. An identity id that no pool knows gets `ResourceNotFoundException` instead of a token. Contributed by @iot-rocket.
- **CloudTrail — new trails start with logging off** — `CreateTrail` left a new trail logging, and `GetTrailStatus` reported a `StartLoggingTime` an hour back and a `LatestDeliveryTime` of now. A new trail now reports `IsLogging` false until `StartLogging`, and `GetTrailStatus` returns only the `StartLoggingTime` and `StopLoggingTime` of calls made (a restart keeps the last stop time), without `LatestDeliveryTime` or empty error strings. Contributed by @iot-rocket.
+- **CloudFormation — EventBridge rules accept a bus ARN** — `AWS::Events::Rule` stored an ARN-valued `EventBusName` as the bus name, so `PutEvents` succeeded without delivering to its targets. Create, update, delete and drift detection now resolve the ARN through the existing EventBridge parser and use the bus name internally.
+
## [1.5.26] — 2026-10-11
### Fixed
diff --git a/ministack/services/cloudformation/drift.py b/ministack/services/cloudformation/drift.py
index e40bfcb0..f3538551 100644
--- a/ministack/services/cloudformation/drift.py
+++ b/ministack/services/cloudformation/drift.py
@@ -33,7 +33,7 @@ import ministack.services.sqs as _sqs
import ministack.services.ssm as _ssm
import ministack.services.stepfunctions as _sfn
-from .provisioners import _STACK_TAG_PROPERTY, _tag_map
+from .provisioners import _STACK_TAG_PROPERTY, _eb_rule_bus_name, _tag_map
logger = logging.getLogger("cloudformation")
@@ -207,7 +207,7 @@ def _exists_in(store_getter):
def _read_events_rule(physical_id, props):
- key = _eb._rule_key(physical_id, props.get("EventBusName", "default"))
+ key = _eb._rule_key(physical_id, _eb_rule_bus_name(props))
return {} if key in _eb._rules else None
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 074c6587..c48fc128 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -3582,9 +3582,19 @@ def _cwlogs_metric_filter_delete(physical_id, props):
# --- EventBridge Rule ---
+
+def _eb_rule_bus_name(props):
+ # CloudFormation accepts a name or ARN, while the service stores names.
+ bus, error = _eb._event_bus_name_from_ref(props.get("EventBusName", "default"))
+ if error:
+ code, message = error
+ raise ValueError(f"AWS::Events::Rule EventBusName: {code}: {message}")
+ return bus
+
+
def _eb_rule_create(logical_id, props, stack_name):
name = props.get("Name") or _physical_name(stack_name, logical_id, max_len=64)
- bus = props.get("EventBusName", "default")
+ bus = _eb_rule_bus_name(props)
key = _eb._rule_key(name, bus)
# The service's own ARN shape: a default-bus rule has no bus segment.
arn = _eb._rule_arn(name, bus)
@@ -3638,8 +3648,8 @@ def _eb_rule_update(physical_id, old_props, new_props, stack_name, logical_id=No
name = new_props.get("Name") or _physical_name(
stack_name, logical_id or physical_id, max_len=64
)
- old_bus = old_props.get("EventBusName", "default")
- new_bus = new_props.get("EventBusName", "default")
+ old_bus = _eb_rule_bus_name(old_props)
+ new_bus = _eb_rule_bus_name(new_props)
old_key = _eb._rule_key(physical_id, old_bus)
rule = _eb._rules.get(old_key)
replaced = _rename_replacement(
@@ -3693,7 +3703,7 @@ def _eb_rule_update(physical_id, old_props, new_props, stack_name, logical_id=No
def _eb_rule_delete(physical_id, props):
- bus = props.get("EventBusName", "default")
+ bus = _eb_rule_bus_name(props)
key = _eb._rule_key(physical_id, bus)
rule = _eb._rules.pop(key, None)
_eb._targets.pop(key, None)
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index 549e2894..642a5347 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -35075,3 +35075,93 @@ def test_cfn_iam_user_generated_name(cfn, iam):
finally:
cfn.delete_stack(StackName=stack_name)
_wait_stack(cfn, stack_name)
+
+
[email protected]("custom_bus", [True, False])
+def test_cfn_events_rule_bus_arn_delivery_and_lifecycle(cfn, eb, sqs, custom_bus):
+ """ARN/name aliases share a rule on create, update, delivery, drift and delete."""
+ uid = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"cfn-rule-bus-arn-{uid}"
+ rule_name = f"cfn-rule-bus-arn-{uid}"
+ bus_name = f"cfn-rule-bus-arn-{uid}" if custom_bus else "default"
+ url = sqs.create_queue(QueueName=f"cfn-rule-bus-arn-{uid}")["QueueUrl"]
+ queue_arn = sqs.get_queue_attributes(
+ QueueUrl=url, AttributeNames=["QueueArn"])["Attributes"]["QueueArn"]
+
+ def template(use_arn, description):
+ resources = {}
+ if custom_bus:
+ resources["Bus"] = {"Type": "AWS::Events::EventBus", "Properties": {"Name": bus_name}}
+ bus_ref = {"Fn::GetAtt": ["Bus", "Arn"]} if custom_bus else {
+ "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/default"}
+ resources["Rule"] = {"Type": "AWS::Events::Rule", "Properties": {
+ "Name": rule_name, "EventBusName": bus_ref if use_arn else bus_name,
+ "Description": description, "EventPattern": {"source": [f"cfn.test.{uid}"]},
+ "Targets": [{"Id": "Q", "Arn": queue_arn}], "Tags": [{"Key": "team", "Value": "test"}]}}
+ return json.dumps({"Resources": resources, "Outputs": {
+ "RuleArn": {"Value": {"Fn::GetAtt": ["Rule", "Arn"]}}}})
+
+ def delivered(marker, use_arn):
+ bus_ref = f"arn:aws:events:us-east-1:000000000000:event-bus/{bus_name}" if use_arn else bus_name
+ response = eb.put_events(Entries=[{
+ "EventBusName": bus_ref, "Source": f"cfn.test.{uid}", "DetailType": "demo",
+ "Detail": json.dumps({"marker": marker})}])
+ assert response["FailedEntryCount"] == 0
+ messages = sqs.receive_message(QueueUrl=url, WaitTimeSeconds=2).get("Messages", [])
+ assert len(messages) == 1
+ assert json.loads(messages[0]["Body"])["detail"] == {"marker": marker}
+ sqs.delete_message(QueueUrl=url, ReceiptHandle=messages[0]["ReceiptHandle"])
+
+ cfn.create_stack(StackName=stack_name, TemplateBody=template(True, "first"))
+ try:
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "CREATE_COMPLETE", _stack_event_reasons(cfn, stack_name)
+ rule = eb.describe_rule(Name=rule_name, EventBusName=bus_name)
+ suffix = f"rule/{bus_name}/{rule_name}" if custom_bus else f"rule/{rule_name}"
+ assert rule["Arn"] == f"arn:aws:events:us-east-1:000000000000:{suffix}"
+ assert _output(stack, "RuleArn") == rule["Arn"]
+ assert rule["EventBusName"] == bus_name
+ assert eb.list_targets_by_rule(Rule=rule_name, EventBusName=bus_name)["Targets"][0]["Arn"] == queue_arn
+ delivered("create", False)
+ delivered("arn-publish", True)
+ drift = cfn.detect_stack_resource_drift(StackName=stack_name, LogicalResourceId="Rule")
+ assert drift["StackResourceDrift"]["StackResourceDriftStatus"] == "IN_SYNC"
+ eb.tag_resource(ResourceARN=rule["Arn"], Tags=[{"Key": "outside", "Value": "kept"}])
+
+ # Switching aliases must not move/delete the rule or lose its targets/tags.
+ for use_arn, description in [(False, "by-name"), (True, "by-arn")]:
+ cfn.update_stack(StackName=stack_name, TemplateBody=template(use_arn, description))
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "UPDATE_COMPLETE", _stack_event_reasons(cfn, stack_name)
+ updated = eb.describe_rule(Name=rule_name, EventBusName=bus_name)
+ assert updated["Arn"] == rule["Arn"]
+ assert updated["Description"] == description
+ assert {"Key": "outside", "Value": "kept"} in eb.list_tags_for_resource(ResourceARN=rule["Arn"])["Tags"]
+ delivered(description, False)
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+ sqs.delete_queue(QueueUrl=url)
+ with pytest.raises(ClientError):
+ eb.describe_rule(Name=rule_name, EventBusName=bus_name)
+
+
[email protected]("bus_ref", [
+ "arn:aws:events:us-west-2:000000000000:event-bus/default",
+ "arn:aws:events:us-east-1:111111111111:event-bus/default",
+ "arn:aws:sqs:us-east-1:000000000000:default",
+ "arn:broken",
+])
+def test_cfn_events_rule_invalid_bus_arn_is_rejected(cfn, eb, bus_ref):
+ """Reuse EventBridge's ARN checks rather than accepting foreign tenants."""
+ uid = _uuid_mod.uuid4().hex[:8]
+ name = f"cfn-rule-bad-arn-{uid}"
+ cfn.create_stack(StackName=name, TemplateBody=json.dumps({"Resources": {
+ "Rule": {"Type": "AWS::Events::Rule", "Properties": {
+ "Name": name, "EventBusName": bus_ref, "EventPattern": {"source": ["cfn.test"]}}}}}))
+ try:
+ stack = _wait_stack(cfn, name)
+ assert stack["StackStatus"] == "ROLLBACK_COMPLETE"
+ assert "AWS::Events::Rule EventBusName:" in _stack_event_reasons(cfn, name)
+ assert not any(rule["Name"] == name for rule in eb.list_rules(EventBusName="default")["Rules"])
+ finally:
+ _delete_cfn_test_stack(cfn, name)