Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(events): resolve dotted pattern keys as nested paths (#1494)
Gabriel Prando7760629088f8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 02dbaae6..043fba07 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,9 +13,11 @@ Versioning follows [Semantic Versioning](https://semver.org/).### Added- **EC2 — opt-in launch options for instance containers (`EC2_DOCKER_FLAGS`)** — a registered image that boots an operating system (systemd as PID 1) needs container options the fixed launch arguments cannot express: unprivileged, `unshare` fails with `Operation not permitted` and the instance terminates at boot. `EC2_DOCKER_FLAGS` now takes a docker-CLI-style string (`--privileged`, `--cap-add`, `-e`, `-v`, `--tmpfs`, `--add-host`, `-m`, `--shm-size`) applied to every instance container; unset, nothing changes. `--init` is refused — instance containers always run with init. Contributed by @iot-rocket.### Fixed+- **EventBridge — dotted pattern keys resolve to the nested path** — [Event Ruler](https://github.com/aws/event-ruler) joins keys with `.` when compiling, so `{"detail.name": [...]}` and `{"detail": {"name": [...]}}` are the same sub-rule on AWS (verified with `TestEventPattern` against the real service); the 1.4 matcher rewrite read a dotted key as one literal segment, so such a rule silently matched nothing — consumer rules written in the dotted form delivered on 1.3.x and stopped after upgrading. Pattern keys are now split on `.` when the compiler extends the path, composing with `$or` expansion, value-side operators, and leaf/object collision handling. The residual divergence — an event *field* literally named `a.b` flattens to the same path on AWS but stays one key here — remains pinned by test; Ruler documents that collision as behaviour that "should not be relied upon". Contributed by @prandogabriel.- **IoT Core — an unresolvable action role fails `CreateTopicRule` instead of silently dropping the rule (`AUTH=true`)** — the role check added with the IAM request authorization answered `200 {}` while storing nothing: the store-layer helper returned the error response as a value and both API handlers discarded it, so a client (or a CloudFormation stack) saw success minus its rule. The check now raises through the same door as invalid rule SQL, `CreateTopicRule` / `ReplaceTopicRule` answer `400 InvalidRequestException` (`Unable to assume role: {arn}`) as real IoT does when it cannot assume the role, and the CloudFormation provisioner fails the resource. With `AUTH=false` nothing changes. Reported by @iot-rocket.- **RDS — Aurora PostgreSQL major-version selectors return the matching catalog** — `DescribeDBEngineVersions` treated `EngineVersion=16` as an exact version and returned nothing. Major-only selectors now return every advertised minor in that family, and `DefaultOnly=true` narrows the result to AWS's configured default minor for that major.+## [1.5.0] — 2026-08-23### Addeddiff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.pyindex c446222d..4ac7239c 100644--- a/ministack/services/eventbridge.py+++ b/ministack/services/eventbridge.py@@ -1372,11 +1372,14 @@ def _compile_object(alternatives, path, obj, expand_or, inside_or, depth):if inside_or and key in _OR_RESERVED_MEMBER_KEYS:raise _InvalidPattern(f"{key} is Ruler reserved fieldName which cannot be used inside $or.")+ # Event Ruler joins keys with ".": a dotted key is the nested path.+ segments = key.split(".") if "." in key else (key,)if isinstance(value, dict):- _compile_object(alternatives, [*path, key], value, expand_or, inside_or, depth + 1)+ _compile_object(alternatives, [*path, *segments], value, expand_or, inside_or,+ depth + 1)elif isinstance(value, list):_validate_value_list(value)- _write_leaf(alternatives, [*path, key], value)+ _write_leaf(alternatives, [*path, *segments], value)else:raise _InvalidPattern(f'"{key}" must be an object or an array')diff --git a/tests/test_eventbridge.py b/tests/test_eventbridge.pyindex ef4127f1..df2e564e 100644--- a/tests/test_eventbridge.py+++ b/tests/test_eventbridge.py@@ -5211,14 +5211,14 @@ def test_eventbridge_unmodelled_top_level_key_is_matchable_not_dropped(eb):assert _matches_event(eb, dict(carried, Source="evil"), {"source": ["v.test"]}) is True-def test_eventbridge_dotted_pattern_key_is_a_distinct_segment(eb):- """A deliberate divergence: AWS resolves ``{"a.b": [...]}`` to the same path as- the nested spelling, where a key holding a dot stays one segment here. Pinned- so the CHANGELOG's divergence list is self-checking rather than asserted."""+def test_eventbridge_dotted_pattern_key_resolves_as_nested_path(eb):+ """Event Ruler joins keys with ".", so the dotted and nested spellings are one+ sub-rule. The residual divergence stays pinned: an event FIELD literally named+ "a.b" flattens to the same path on AWS, where it stays one key here."""dotted = {"a.b": ["v"]}- assert _pattern_matches(eb, dotted, {"a": {"b": "v"}}) is False- assert _pattern_matches(eb, dotted, {"a.b": "v"}) is True+ assert _pattern_matches(eb, dotted, {"a": {"b": "v"}}) is Trueassert _pattern_matches(eb, {"a": {"b": ["v"]}}, {"a": {"b": "v"}}) is True+ assert _pattern_matches(eb, dotted, {"a.b": "v"}) is False # AWS: Truedef test_eventbridge_pattern_nesting_bound_clears_real_patterns(eb):@@ -5413,3 +5413,82 @@ def test_eventbridge_case_insensitive_suffix_does_not_scan_quadratically():assert _eb._matches_content_filter(value, {"suffix": {"equals-ignore-case": ".PNG"}}) is Trueassert time.monotonic() - started < 1.0+++# ---------------------------------------------------------------------------+# Dotted pattern keys — a dotted key and the nested form are the same sub-rule.+# ---------------------------------------------------------------------------++def test_eventbridge_dotted_key_matches_nested_field(eb):+ assert _matches_event(+ eb,+ {"source": "dot.test", "detail-type": "T", "detail": {"name": "user.created"}},+ {"detail.name": ["user.created"]}) is True+ assert _matches_event(+ eb,+ {"source": "dot.test", "detail-type": "T", "detail": {"name": "other"}},+ {"detail.name": ["user.created"]}) is False+++def test_eventbridge_dotted_key_equals_nested_form(eb):+ event = {"source": "dot.test", "detail-type": "T",+ "detail": {"state": {"status": "running"}}}+ assert _matches_event(eb, event, {"detail.state.status": ["running"]}) is True+ assert _matches_event(eb, event, {"detail": {"state.status": ["running"]}}) is True+ assert _matches_event(eb, event, {"detail": {"state": {"status": ["running"]}}}) is True+++def test_eventbridge_dotted_key_with_object_value(eb):+ event = {"source": "dot.test", "detail-type": "T",+ "detail": {"state": {"status": "running"}}}+ assert _matches_event(eb, event, {"detail.state": {"status": ["running"]}}) is True+ assert _matches_event(eb, event, {"detail.state": {"status": ["stopped"]}}) is False+++def test_eventbridge_dotted_key_operators(eb):+ event = {"source": "dot.test", "detail-type": "T", "detail": {"name": "order.paid"}}+ assert _matches_event(eb, event, {"detail.name": [{"prefix": "order."}]}) is True+ assert _matches_event(eb, event, {"detail.name": [{"exists": True}]}) is True+ assert _matches_event(eb, event, {"detail.other": [{"exists": False}]}) is True+++def test_eventbridge_dotted_key_inside_or(eb):+ event = {"source": "dot.test", "detail-type": "T", "detail": {"name": "a"}}+ pattern = {"$or": [{"detail.name": ["a"]}, {"detail.name": ["b"]}]}+ assert _matches_event(eb, event, pattern) is True+ assert _matches_event(+ eb, {"source": "dot.test", "detail-type": "T", "detail": {"name": "c"}},+ pattern) is False+++def test_eventbridge_dotted_key_leaf_collision_is_last_write_wins(eb):+ """Both spellings write the same leaf, so document order decides."""+ event = {"source": "dot.test", "detail-type": "T", "detail": {"name": "b"}}+ assert _matches_event(+ eb, event, {"detail.name": ["a"], "detail": {"name": ["b"]}}) is True+ assert _matches_event(+ eb, event, {"detail": {"name": ["b"]}, "detail.name": ["a"]}) is False+++def test_eventbridge_dotted_key_rule_delivers_to_sqs(eb, sqs):+ queue_name = f"dotted-key-{_uuid_mod.uuid4().hex[:8]}"+ rule_name = f"dotted-key-{_uuid_mod.uuid4().hex[:8]}"+ q_url = sqs.create_queue(QueueName=queue_name)["QueueUrl"]+ queue_arn = sqs.get_queue_attributes(+ QueueUrl=q_url, AttributeNames=["QueueArn"])["Attributes"]["QueueArn"]+ eb.put_rule(Name=rule_name,+ EventPattern=json.dumps({"detail.name": ["dotted.ping"]}),+ State="ENABLED")+ eb.put_targets(Rule=rule_name, Targets=[{"Id": "1", "Arn": queue_arn}])++ eb.put_events(Entries=[{+ "Source": "dot.test",+ "DetailType": "T",+ "Detail": json.dumps({"name": "dotted.ping", "payload": {"ok": True}}),+ "EventBusName": "default",+ }])++ msgs = sqs.receive_message(QueueUrl=q_url, MaxNumberOfMessages=1, WaitTimeSeconds=2)+ assert len(msgs.get("Messages", [])) == 1+ body = json.loads(msgs["Messages"][0]["Body"])+ assert body["detail"]["name"] == "dotted.ping"