Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samtranslator/model/stepfunctions/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/validator/sam_schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@
"Pattern": {
"type": "object"
},
"State": {
"type": "string"
},
"DeadLetterConfig": {
"additionalProperties": false,
"properties": {
Expand Down
6 changes: 6 additions & 0 deletions tests/model/eventsources/test_eventbridge_rule_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/model/stepfunctions/test_eventbridge_rule_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 2 additions & 0 deletions tests/translator/input/eventbridgerule_with_dlq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Resources:
Type: Schedule
Properties:
Schedule: 'rate(1 minute)'
State: ENABLED
DeadLetterConfig:
Type: SQS
TriggeredFunction:
Expand All @@ -23,6 +24,7 @@ Resources:
Type: EventBridgeRule
Properties:
EventBusName: ExternalEventBridge
State: ENABLED
Pattern:
detail:
state:
Expand Down
1 change: 1 addition & 0 deletions tests/translator/input/state_machine_with_cwe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Resources:
CWEvent:
Type: CloudWatchEvent
Properties:
State: ENABLED
Pattern:
detail:
state:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
}
},
"EventBusName": "ExternalEventBridge",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down Expand Up @@ -213,6 +214,7 @@
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]
}
},
"State": "ENABLED",
"Targets": [
{
"RoleArn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
}
},
"EventBusName": "ExternalEventBridge",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down Expand Up @@ -213,6 +214,7 @@
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]
}
},
"State": "ENABLED",
"Targets": [
{
"RoleArn": {
Expand Down
4 changes: 3 additions & 1 deletion tests/translator/output/eventbridgerule_with_dlq.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
]
}
},
"EventBusName": "ExternalEventBridge",
"EventBusName": "ExternalEventBridge",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down Expand Up @@ -213,6 +214,7 @@
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State" : "ENABLED",
"Targets": [
{
"DeadLetterConfig": {
Expand Down
1 change: 1 addition & 0 deletions tests/translator/output/state_machine_with_cwe.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]
}
},
"State": "ENABLED",
"Targets": [
{
"RoleArn": {
Expand Down