@@ -1634,6 +1634,105 @@ def test_process_to_single_matching_rules_single_target(
1634
1634
)
1635
1635
snapshot .match (f"events-{ source } " , events )
1636
1636
1637
+ @markers .aws .validated
1638
+ def test_process_pattern_to_single_matching_rules_single_target (
1639
+ self ,
1640
+ create_lambda_function ,
1641
+ events_create_event_bus ,
1642
+ events_put_rule ,
1643
+ aws_client ,
1644
+ snapshot ,
1645
+ ):
1646
+ """Three rules with all the same lambda target, but different patterns as condition.
1647
+ The lambda should onl be invoked by the rule matching the event pattern."""
1648
+
1649
+ bus_name = f"test-bus-{ short_uid ()} "
1650
+ events_create_event_bus (Name = bus_name )
1651
+
1652
+ # create lambda target
1653
+ function_name = f"lambda-func-{ short_uid ()} "
1654
+ create_lambda_response = create_lambda_function (
1655
+ handler_file = TEST_LAMBDA_PYTHON_ECHO ,
1656
+ func_name = function_name ,
1657
+ runtime = Runtime .python3_12 ,
1658
+ )
1659
+ lambda_function_arn = create_lambda_response ["CreateFunctionResponse" ]["FunctionArn" ]
1660
+
1661
+ # create rules
1662
+ input_path_map = {"detail" : "$.detail" }
1663
+ patterns = [
1664
+ {"detail" : {"payload" : {"id" : [{"exists" : True }]}}},
1665
+ {"detail" : {"id" : [{"exists" : True }]}},
1666
+ ]
1667
+ input_transformers = [
1668
+ {
1669
+ "InputPathsMap" : input_path_map ,
1670
+ "InputTemplate" : '{"detail-payload-with-id": <detail>}' ,
1671
+ },
1672
+ {
1673
+ "InputPathsMap" : input_path_map ,
1674
+ "InputTemplate" : '{"detail-with-id": <detail>}' ,
1675
+ },
1676
+ ]
1677
+ for i , pattern , input_transformer in zip (range (3 ), patterns , input_transformers ):
1678
+ rule_name = f"test-rule-{ i } -{ short_uid ()} "
1679
+ rule = events_put_rule (
1680
+ Name = rule_name ,
1681
+ EventBusName = bus_name ,
1682
+ EventPattern = json .dumps (pattern ),
1683
+ State = "ENABLED" ,
1684
+ )
1685
+ rule_arn = rule ["RuleArn" ]
1686
+
1687
+ aws_client .lambda_ .add_permission (
1688
+ FunctionName = function_name ,
1689
+ StatementId = f"{ rule_name } -Event" ,
1690
+ Action = "lambda:InvokeFunction" ,
1691
+ Principal = "events.amazonaws.com" ,
1692
+ SourceArn = rule_arn ,
1693
+ )
1694
+
1695
+ target_id = f"test-target-{ i } -{ short_uid ()} "
1696
+ aws_client .events .put_targets (
1697
+ Rule = rule_name ,
1698
+ EventBusName = bus_name ,
1699
+ Targets = [
1700
+ {
1701
+ "Id" : target_id ,
1702
+ "Arn" : lambda_function_arn ,
1703
+ "InputTransformer" : input_transformer ,
1704
+ }
1705
+ ],
1706
+ )
1707
+
1708
+ details = [
1709
+ {"payload" : {"id" : "123" }},
1710
+ {"id" : "123" },
1711
+ ]
1712
+ for i , detail in zip (range (3 ), details ):
1713
+ num_events = i + 1
1714
+ aws_client .events .put_events (
1715
+ Entries = [
1716
+ {
1717
+ "EventBusName" : bus_name ,
1718
+ "Source" : TEST_EVENT_PATTERN_NO_DETAIL ["source" ][0 ],
1719
+ "DetailType" : TEST_EVENT_PATTERN_NO_DETAIL ["detail-type" ][0 ],
1720
+ "Detail" : json .dumps (detail ),
1721
+ }
1722
+ ],
1723
+ )
1724
+
1725
+ # check lambda invocation
1726
+ events = retry (
1727
+ check_expected_lambda_log_events_length ,
1728
+ retries = 3 ,
1729
+ sleep = 1 ,
1730
+ function_name = function_name ,
1731
+ expected_length = num_events ,
1732
+ logs_client = aws_client .logs ,
1733
+ )
1734
+ snapshot .match (f"events-{ num_events } " , events )
1735
+
1637
1736
1638
1737
class TestEventPattern :
1639
1738
@markers .aws .validated
0 commit comments