12
12
from samtranslator .model .events import EventsRule
13
13
from samtranslator .model .eventsources .pull import SQS
14
14
from samtranslator .model .sqs import SQSQueue , SQSQueuePolicy , SQSQueuePolicies
15
+ from samtranslator .model .eventbridge_utils import EventBridgeRuleUtils
15
16
from samtranslator .model .iot import IotTopicRule
16
17
from samtranslator .model .cognito import CognitoUserPool
17
18
from samtranslator .translator import logical_id_generator
@@ -94,6 +95,8 @@ class Schedule(PushEventSource):
94
95
"Enabled" : PropertyType (False , is_type (bool )),
95
96
"Name" : PropertyType (False , is_str ()),
96
97
"Description" : PropertyType (False , is_str ()),
98
+ "DeadLetterConfig" : PropertyType (False , is_type (dict )),
99
+ "RetryPolicy" : PropertyType (False , is_type (dict )),
97
100
}
98
101
99
102
def to_cloudformation (self , ** kwargs ):
@@ -118,16 +121,23 @@ def to_cloudformation(self, **kwargs):
118
121
events_rule .State = "ENABLED" if self .Enabled else "DISABLED"
119
122
events_rule .Name = self .Name
120
123
events_rule .Description = self .Description
121
- events_rule .Targets = [self ._construct_target (function )]
122
124
123
125
source_arn = events_rule .get_runtime_attr ("arn" )
126
+ dlq_queue_arn = None
127
+ if self .DeadLetterConfig is not None :
128
+ EventBridgeRuleUtils .validate_dlq_config (self .logical_id , self .DeadLetterConfig )
129
+ dlq_queue_arn , dlq_resources = EventBridgeRuleUtils .get_dlq_queue_arn_and_resources (self , source_arn )
130
+ resources .extend (dlq_resources )
131
+
132
+ events_rule .Targets = [self ._construct_target (function , dlq_queue_arn )]
133
+
124
134
if CONDITION in function .resource_attributes :
125
135
events_rule .set_resource_attribute (CONDITION , function .resource_attributes [CONDITION ])
126
136
resources .append (self ._construct_permission (function , source_arn = source_arn ))
127
137
128
138
return resources
129
139
130
- def _construct_target (self , function ):
140
+ def _construct_target (self , function , dead_letter_queue_arn = None ):
131
141
"""Constructs the Target property for the EventBridge Rule.
132
142
133
143
:returns: the Target property
@@ -137,6 +147,12 @@ def _construct_target(self, function):
137
147
if self .Input is not None :
138
148
target ["Input" ] = self .Input
139
149
150
+ if self .DeadLetterConfig is not None :
151
+ target ["DeadLetterConfig" ] = {"Arn" : dead_letter_queue_arn }
152
+
153
+ if self .RetryPolicy is not None :
154
+ target ["RetryPolicy" ] = self .RetryPolicy
155
+
140
156
return target
141
157
142
158
@@ -148,6 +164,8 @@ class CloudWatchEvent(PushEventSource):
148
164
property_types = {
149
165
"EventBusName" : PropertyType (False , is_str ()),
150
166
"Pattern" : PropertyType (False , is_type (dict )),
167
+ "DeadLetterConfig" : PropertyType (False , is_type (dict )),
168
+ "RetryPolicy" : PropertyType (False , is_type (dict )),
151
169
"Input" : PropertyType (False , is_str ()),
152
170
"InputPath" : PropertyType (False , is_str ()),
153
171
"Target" : PropertyType (False , is_type (dict )),
@@ -171,18 +189,24 @@ def to_cloudformation(self, **kwargs):
171
189
events_rule = EventsRule (self .logical_id )
172
190
events_rule .EventBusName = self .EventBusName
173
191
events_rule .EventPattern = self .Pattern
174
- events_rule .Targets = [self ._construct_target (function )]
192
+ source_arn = events_rule .get_runtime_attr ("arn" )
193
+
194
+ dlq_queue_arn = None
195
+ if self .DeadLetterConfig is not None :
196
+ EventBridgeRuleUtils .validate_dlq_config (self .logical_id , self .DeadLetterConfig )
197
+ dlq_queue_arn , dlq_resources = EventBridgeRuleUtils .get_dlq_queue_arn_and_resources (self , source_arn )
198
+ resources .extend (dlq_resources )
199
+
200
+ events_rule .Targets = [self ._construct_target (function , dlq_queue_arn )]
175
201
if CONDITION in function .resource_attributes :
176
202
events_rule .set_resource_attribute (CONDITION , function .resource_attributes [CONDITION ])
177
203
178
204
resources .append (events_rule )
179
-
180
- source_arn = events_rule .get_runtime_attr ("arn" )
181
205
resources .append (self ._construct_permission (function , source_arn = source_arn ))
182
206
183
207
return resources
184
208
185
- def _construct_target (self , function ):
209
+ def _construct_target (self , function , dead_letter_queue_arn = None ):
186
210
"""Constructs the Target property for the CloudWatch Events/EventBridge Rule.
187
211
188
212
:returns: the Target property
@@ -195,6 +219,13 @@ def _construct_target(self, function):
195
219
196
220
if self .InputPath is not None :
197
221
target ["InputPath" ] = self .InputPath
222
+
223
+ if self .DeadLetterConfig is not None :
224
+ target ["DeadLetterConfig" ] = {"Arn" : dead_letter_queue_arn }
225
+
226
+ if self .RetryPolicy is not None :
227
+ target ["RetryPolicy" ] = self .RetryPolicy
228
+
198
229
return target
199
230
200
231
0 commit comments