@@ -32,14 +32,29 @@ def configure_dlq(event):
32
32
33
33
aws_lambda = boto3 .client ("lambda" )
34
34
lambda_arn = event ['ResourceProperties' ]['LambdaArn' ]
35
- dlq_arn = event ['ResourceProperties' ]['DLQ' ]['DLQArn' ]
35
+ dlq_arn = event ['ResourceProperties' ]['DLQ' ]['DLQArn' ]
36
+
36
37
aws_lambda .update_function_configuration (
37
38
FunctionName = lambda_arn ,
38
39
DeadLetterConfig = {
39
40
'TargetArn' : dlq_arn
40
41
},
41
42
)
42
43
44
+ if event ['RequestType' ] == 'Update' :
45
+ print ('updating dlq event source mapping...' )
46
+ # remove mapping and recreate it on update
47
+ mappings = aws_lambda .list_event_source_mappings (
48
+ FunctionName = lambda_arn ,
49
+ )["EventSourceMappings" ]
50
+
51
+ for mapping in mappings :
52
+ if mapping ["EventSourceArn" ] == dlq_arn :
53
+ print ('deleting previous dlq event source mapping...' )
54
+ aws_lambda .delete_event_source_mapping (UUID = mapping ["UUID" ])
55
+
56
+ time .sleep (15 ) # give the change a little time to propagate
57
+
43
58
# Create event source mapping
44
59
aws_lambda .create_event_source_mapping (
45
60
EventSourceArn = dlq_arn ,
@@ -184,7 +199,8 @@ def update(self):
184
199
err = self .delete ()
185
200
if err :
186
201
raise Exception (err )
187
-
202
+
203
+ time .sleep (15 )
188
204
return self .create ()
189
205
190
206
@handle_exceptions
@@ -325,6 +341,7 @@ def update(self):
325
341
err = self .delete ()
326
342
if err :
327
343
raise Exception (err )
344
+ time .sleep (15 )
328
345
return self .create ()
329
346
330
347
@handle_exceptions
@@ -430,6 +447,7 @@ def update(self):
430
447
err = self .delete ()
431
448
if err :
432
449
raise Exception (err )
450
+ time .sleep (15 )
433
451
return self .create ()
434
452
435
453
@handle_exceptions
0 commit comments