diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index b53e9e1dc..227c9826b 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -97,6 +97,7 @@ class Schedule(PushEventSource): principal = "events.amazonaws.com" property_types = { "Schedule": PropertyType(True, is_str()), # type: ignore[no-untyped-call, no-untyped-call] + "RuleName": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] "Input": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] "Enabled": PropertyType(False, is_type(bool)), # type: ignore[no-untyped-call, no-untyped-call] "State": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] @@ -180,6 +181,7 @@ class CloudWatchEvent(PushEventSource): principal = "events.amazonaws.com" property_types = { "EventBusName": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] + "RuleName": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] "Pattern": PropertyType(False, is_type(dict)), # type: ignore[no-untyped-call, no-untyped-call] "DeadLetterConfig": PropertyType(False, is_type(dict)), # type: ignore[no-untyped-call, no-untyped-call] "RetryPolicy": PropertyType(False, is_type(dict)), # type: ignore[no-untyped-call, no-untyped-call] @@ -210,6 +212,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] events_rule = EventsRule(self.logical_id, attributes=passthrough_resource_attributes) # type: ignore[no-untyped-call] events_rule.EventBusName = self.EventBusName # type: ignore[attr-defined] events_rule.EventPattern = self.Pattern # type: ignore[attr-defined] + events_rule.Name = self.RuleName # type: ignore[attr-defined] source_arn = events_rule.get_runtime_attr("arn") # type: ignore[no-untyped-call] dlq_queue_arn = None diff --git a/samtranslator/model/stepfunctions/events.py b/samtranslator/model/stepfunctions/events.py index cc3fbada4..4880fe05b 100644 --- a/samtranslator/model/stepfunctions/events.py +++ b/samtranslator/model/stepfunctions/events.py @@ -165,6 +165,7 @@ class CloudWatchEvent(EventSource): principal = "events.amazonaws.com" property_types = { "EventBusName": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] + "RuleName": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] "Pattern": PropertyType(False, is_type(dict)), # type: ignore[no-untyped-call, no-untyped-call] "Input": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] "InputPath": PropertyType(False, is_str()), # type: ignore[no-untyped-call, no-untyped-call] @@ -190,6 +191,7 @@ def to_cloudformation(self, resource, **kwargs): # type: ignore[no-untyped-def] events_rule = EventsRule(self.logical_id, attributes=passthrough_resource_attributes) # type: ignore[no-untyped-call] events_rule.EventBusName = self.EventBusName # type: ignore[attr-defined] events_rule.EventPattern = self.Pattern # type: ignore[attr-defined] + events_rule.Name = self.RuleName # type: ignore[attr-defined] if self.State: # type: ignore[attr-defined] events_rule.State = self.State # type: ignore[attr-defined] diff --git a/samtranslator/validator/sam_schema/schema.json b/samtranslator/validator/sam_schema/schema.json index 83a31d87f..393004f6b 100644 --- a/samtranslator/validator/sam_schema/schema.json +++ b/samtranslator/validator/sam_schema/schema.json @@ -374,6 +374,9 @@ "State": { "type": "string" }, + "RuleName": { + "type": "string" + }, "DeadLetterConfig": { "additionalProperties": false, "properties": { diff --git a/tests/model/eventsources/test_eventbridge_rule_source.py b/tests/model/eventsources/test_eventbridge_rule_source.py index 345650bb9..31fb93a85 100644 --- a/tests/model/eventsources/test_eventbridge_rule_source.py +++ b/tests/model/eventsources/test_eventbridge_rule_source.py @@ -32,6 +32,12 @@ def test_state_when_provided(self): state = cfn[0].State self.assertEqual(state, "DISABLED") + def test_name_when_provided(self): + self.eb_event_source.RuleName = "MyRule" + cfn = self.eb_event_source.to_cloudformation(function=self.func) + name = cfn[0].Name + self.assertEqual(name, "MyRule") + def test_to_cloudformation_with_retry_policy(self): retry_policy = {"MaximumRetryAttempts": "10", "MaximumEventAgeInSeconds": "300"} self.eb_event_source.RetryPolicy = retry_policy diff --git a/tests/model/stepfunctions/test_eventbridge_rule_source.py b/tests/model/stepfunctions/test_eventbridge_rule_source.py index 2b1032928..4f6654210 100644 --- a/tests/model/stepfunctions/test_eventbridge_rule_source.py +++ b/tests/model/stepfunctions/test_eventbridge_rule_source.py @@ -39,3 +39,9 @@ def test_to_cloudformation_with_state(self): resources = self.eb_event_source.to_cloudformation(resource=self.state_machine) state = resources[0].State self.assertEqual(state, "DISABLED") + + def test_name_when_provided(self): + self.eb_event_source.RuleName = "MyRule" + resources = self.eb_event_source.to_cloudformation(resource=self.state_machine) + event_rule = resources[0] + self.assertEqual(event_rule.Name, "MyRule") diff --git a/tests/translator/input/eventbridgerule_with_dlq.yaml b/tests/translator/input/eventbridgerule_with_dlq.yaml index e651e6520..00422fde1 100644 --- a/tests/translator/input/eventbridgerule_with_dlq.yaml +++ b/tests/translator/input/eventbridgerule_with_dlq.yaml @@ -24,6 +24,7 @@ Resources: Type: EventBridgeRule Properties: EventBusName: ExternalEventBridge + RuleName: MyRule State: ENABLED Pattern: detail: diff --git a/tests/translator/input/state_machine_with_cwe.yaml b/tests/translator/input/state_machine_with_cwe.yaml index ee43797ff..cb08710de 100644 --- a/tests/translator/input/state_machine_with_cwe.yaml +++ b/tests/translator/input/state_machine_with_cwe.yaml @@ -8,6 +8,7 @@ Resources: CWEvent: Type: CloudWatchEvent Properties: + RuleName: MyRule State: ENABLED Pattern: detail: diff --git a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json index 813b02553..65c77a3a5 100644 --- a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json @@ -172,6 +172,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ { diff --git a/tests/translator/output/aws-cn/state_machine_with_cwe.json b/tests/translator/output/aws-cn/state_machine_with_cwe.json index fb1f07623..b674effc3 100644 --- a/tests/translator/output/aws-cn/state_machine_with_cwe.json +++ b/tests/translator/output/aws-cn/state_machine_with_cwe.json @@ -25,6 +25,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ { diff --git a/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json index ae0524838..0c7f07483 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json @@ -172,6 +172,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ { diff --git a/tests/translator/output/aws-us-gov/state_machine_with_cwe.json b/tests/translator/output/aws-us-gov/state_machine_with_cwe.json index fb1f07623..b674effc3 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_cwe.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_cwe.json @@ -25,6 +25,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ { diff --git a/tests/translator/output/eventbridgerule_with_dlq.json b/tests/translator/output/eventbridgerule_with_dlq.json index a7abb393b..2d5c4826c 100644 --- a/tests/translator/output/eventbridgerule_with_dlq.json +++ b/tests/translator/output/eventbridgerule_with_dlq.json @@ -172,6 +172,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ { diff --git a/tests/translator/output/state_machine_with_cwe.json b/tests/translator/output/state_machine_with_cwe.json index fb1f07623..b674effc3 100644 --- a/tests/translator/output/state_machine_with_cwe.json +++ b/tests/translator/output/state_machine_with_cwe.json @@ -25,6 +25,7 @@ ] } }, + "Name": "MyRule", "State": "ENABLED", "Targets": [ {