From 9e9248e3173bc9b25c28ada4dabc9d0e0e0f79ab Mon Sep 17 00:00:00 2001 From: Seb Kasprzak Date: Tue, 11 Oct 2022 10:21:28 +1100 Subject: [PATCH 1/4] Add ability to set State of EventBridge Rule --- samtranslator/validator/sam_schema/schema.json | 3 +++ tests/model/eventsources/test_eventbridge_rule_source.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/samtranslator/validator/sam_schema/schema.json b/samtranslator/validator/sam_schema/schema.json index 4cf7f1f5ce..83a31d87fe 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 252f3ce074..1860e052bf 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 From cfea8b7b8eb7f634043d71ef9bdf8222ca1eae24 Mon Sep 17 00:00:00 2001 From: Seb Kasprzak Date: Wed, 12 Oct 2022 10:40:33 +1100 Subject: [PATCH 2/4] Add ability to set Name of EventBridge Rule in SFN --- samtranslator/model/stepfunctions/events.py | 4 ++++ tests/model/eventsources/test_eventbridge_rule_source.py | 4 ++-- tests/model/stepfunctions/test_eventbridge_rule_source.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/samtranslator/model/stepfunctions/events.py b/samtranslator/model/stepfunctions/events.py index 6407d48669..33c0d000c5 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/tests/model/eventsources/test_eventbridge_rule_source.py b/tests/model/eventsources/test_eventbridge_rule_source.py index 1860e052bf..345650bb95 100644 --- a/tests/model/eventsources/test_eventbridge_rule_source.py +++ b/tests/model/eventsources/test_eventbridge_rule_source.py @@ -27,10 +27,10 @@ def test_target_id_when_provided(self): self.assertEqual(target_id, "MyTargetId") def test_state_when_provided(self): - self.eb_event_source.State = "Disabled" + self.eb_event_source.State = "DISABLED" cfn = self.eb_event_source.to_cloudformation(function=self.func) state = cfn[0].State - self.assertEqual(state, "Disabled") + self.assertEqual(state, "DISABLED") def test_to_cloudformation_with_retry_policy(self): retry_policy = {"MaximumRetryAttempts": "10", "MaximumEventAgeInSeconds": "300"} diff --git a/tests/model/stepfunctions/test_eventbridge_rule_source.py b/tests/model/stepfunctions/test_eventbridge_rule_source.py index 8e1ef412e9..2b10329287 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") From 587d8e11de92cb21b4c825ea8fd98522859c486d Mon Sep 17 00:00:00 2001 From: Seb Kasprzak Date: Thu, 13 Oct 2022 16:12:48 +1100 Subject: [PATCH 3/4] Added transform tests for State property of Eventbridge rule for Event Source and SFN --- tests/translator/input/eventbridgerule_with_dlq.yaml | 2 ++ tests/translator/output/aws-cn/eventbridgerule_with_dlq.json | 2 ++ .../output/aws-us-gov/eventbridgerule_with_dlq.json | 2 ++ tests/translator/output/eventbridgerule_with_dlq.json | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/translator/input/eventbridgerule_with_dlq.yaml b/tests/translator/input/eventbridgerule_with_dlq.yaml index 7bb7dc59db..e651e6520a 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/output/aws-cn/eventbridgerule_with_dlq.json b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json index 6f6fa0460f..42a20c35ab 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-us-gov/eventbridgerule_with_dlq.json b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json index b5dd4901b8..17da23c66c 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/eventbridgerule_with_dlq.json b/tests/translator/output/eventbridgerule_with_dlq.json index 2d5c96a915..5e9bd4ab01 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": { From ce75152cf0f1418698bb88a7fda724203590ddd8 Mon Sep 17 00:00:00 2001 From: Sebastian Kasprzak Date: Thu, 13 Oct 2022 18:49:46 +1100 Subject: [PATCH 4/4] added transform test for SFN as well --- tests/translator/input/state_machine_with_cwe.yaml | 1 + tests/translator/output/aws-cn/state_machine_with_cwe.json | 1 + tests/translator/output/aws-us-gov/state_machine_with_cwe.json | 1 + tests/translator/output/state_machine_with_cwe.json | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/translator/input/state_machine_with_cwe.yaml b/tests/translator/input/state_machine_with_cwe.yaml index 488d8dc995..ee43797ffc 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/state_machine_with_cwe.json b/tests/translator/output/aws-cn/state_machine_with_cwe.json index 04164e9434..95940a3534 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/state_machine_with_cwe.json b/tests/translator/output/aws-us-gov/state_machine_with_cwe.json index 04164e9434..95940a3534 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/state_machine_with_cwe.json b/tests/translator/output/state_machine_with_cwe.json index 04164e9434..95940a3534 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": {