diff --git a/samtranslator/model/stepfunctions/events.py b/samtranslator/model/stepfunctions/events.py index 6407d4866..33c0d000c 100644 --- a/samtranslator/model/stepfunctions/events.py +++ b/samtranslator/model/stepfunctions/events.py @@ -170,6 +170,7 @@ class CloudWatchEvent(EventSource): "InputPath": PropertyType(False, is_str()), "DeadLetterConfig": PropertyType(False, is_type(dict)), "RetryPolicy": PropertyType(False, is_type(dict)), + "State": PropertyType(False, is_str()), } @cw_timer(prefix=SFN_EVETSOURCE_METRIC_PREFIX) @@ -190,6 +191,9 @@ def to_cloudformation(self, resource, **kwargs): events_rule.EventBusName = self.EventBusName events_rule.EventPattern = self.Pattern + if self.State: + events_rule.State = self.State + resources.append(events_rule) role = self._construct_role(resource, permissions_boundary) diff --git a/samtranslator/validator/sam_schema/schema.json b/samtranslator/validator/sam_schema/schema.json index 4cf7f1f5c..83a31d87f 100644 --- a/samtranslator/validator/sam_schema/schema.json +++ b/samtranslator/validator/sam_schema/schema.json @@ -371,6 +371,9 @@ "Pattern": { "type": "object" }, + "State": { + "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 252f3ce07..345650bb9 100644 --- a/tests/model/eventsources/test_eventbridge_rule_source.py +++ b/tests/model/eventsources/test_eventbridge_rule_source.py @@ -26,6 +26,12 @@ def test_target_id_when_provided(self): target_id = cfn[0].Targets[0]["Id"] self.assertEqual(target_id, "MyTargetId") + def test_state_when_provided(self): + self.eb_event_source.State = "DISABLED" + cfn = self.eb_event_source.to_cloudformation(function=self.func) + state = cfn[0].State + self.assertEqual(state, "DISABLED") + 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 8e1ef412e..2b1032928 100644 --- a/tests/model/stepfunctions/test_eventbridge_rule_source.py +++ b/tests/model/stepfunctions/test_eventbridge_rule_source.py @@ -33,3 +33,9 @@ def test_to_cloudformation_with_dlq_generated_with_intrinsic_function_custom_log self.eb_event_source.DeadLetterConfig = dead_letter_config with self.assertRaises(InvalidEventException): self.eb_event_source.to_cloudformation(resource=self.state_machine) + + def test_to_cloudformation_with_state(self): + self.eb_event_source.State = "DISABLED" + resources = self.eb_event_source.to_cloudformation(resource=self.state_machine) + state = resources[0].State + self.assertEqual(state, "DISABLED") diff --git a/tests/translator/input/eventbridgerule_with_dlq.yaml b/tests/translator/input/eventbridgerule_with_dlq.yaml index 7bb7dc59d..e651e6520 100644 --- a/tests/translator/input/eventbridgerule_with_dlq.yaml +++ b/tests/translator/input/eventbridgerule_with_dlq.yaml @@ -10,6 +10,7 @@ Resources: Type: Schedule Properties: Schedule: 'rate(1 minute)' + State: ENABLED DeadLetterConfig: Type: SQS TriggeredFunction: @@ -23,6 +24,7 @@ Resources: Type: EventBridgeRule Properties: EventBusName: ExternalEventBridge + State: ENABLED Pattern: detail: state: diff --git a/tests/translator/input/state_machine_with_cwe.yaml b/tests/translator/input/state_machine_with_cwe.yaml index 488d8dc99..ee43797ff 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: + State: ENABLED Pattern: detail: state: diff --git a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json index 6f6fa0460..42a20c35a 100644 --- a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json @@ -79,6 +79,7 @@ } }, "EventBusName": "ExternalEventBridge", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { @@ -213,6 +214,7 @@ "Type": "AWS::Events::Rule", "Properties": { "ScheduleExpression": "rate(1 minute)", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { 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 04164e943..95940a353 100644 --- a/tests/translator/output/aws-cn/state_machine_with_cwe.json +++ b/tests/translator/output/aws-cn/state_machine_with_cwe.json @@ -10,6 +10,7 @@ ] } }, + "State": "ENABLED", "Targets": [ { "RoleArn": { 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 b5dd4901b..17da23c66 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json @@ -79,6 +79,7 @@ } }, "EventBusName": "ExternalEventBridge", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { @@ -213,6 +214,7 @@ "Type": "AWS::Events::Rule", "Properties": { "ScheduleExpression": "rate(1 minute)", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { 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 04164e943..95940a353 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 @@ -10,6 +10,7 @@ ] } }, + "State": "ENABLED", "Targets": [ { "RoleArn": { diff --git a/tests/translator/output/eventbridgerule_with_dlq.json b/tests/translator/output/eventbridgerule_with_dlq.json index 2d5c96a91..5e9bd4ab0 100644 --- a/tests/translator/output/eventbridgerule_with_dlq.json +++ b/tests/translator/output/eventbridgerule_with_dlq.json @@ -78,7 +78,8 @@ ] } }, - "EventBusName": "ExternalEventBridge", + "EventBusName": "ExternalEventBridge", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { @@ -213,6 +214,7 @@ "Type": "AWS::Events::Rule", "Properties": { "ScheduleExpression": "rate(1 minute)", + "State" : "ENABLED", "Targets": [ { "DeadLetterConfig": { diff --git a/tests/translator/output/state_machine_with_cwe.json b/tests/translator/output/state_machine_with_cwe.json index 04164e943..95940a353 100644 --- a/tests/translator/output/state_machine_with_cwe.json +++ b/tests/translator/output/state_machine_with_cwe.json @@ -10,6 +10,7 @@ ] } }, + "State": "ENABLED", "Targets": [ { "RoleArn": {