Skip to content

Commit b4c5b0f

Browse files
committed
State mach: fix: delete stale DbStatus after each wait
Fixes a subtle bug introduced by the use of the JSONata transition operator with regular expression matches ( ~> |$|{'DbStatus': $match(...)} ) or with queries that can fail. A failed match is very unlikely, and would signal a change in the Aurora API. A failed query (of an RDS DescribeDBInstances result) is unlikely but possible. So, it's important to handle this case correctly. A failed match or failed query returns undefined, which leaves the key out of the merge object. If DbStatus was set successfully on a previous iteration, the old value persists. To prevent this, I now delete DbStatus, along with past Error and Cause keys, at the end (Output) of the Wait state. I chose not to do this in the Dispatch (former name) state, at the start of an iteration, because that is a Choice state and it would be necessary to duplicate the deletion code for DB_INSTANCE and CLUSTER.
1 parent 9cfe89f commit b4c5b0f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

step_stay_stopped_aws_rds_aurora.asl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
"Wait": {
146146
"Type": "Wait",
147147
"Seconds": "{% $Constant.StepFnWaitSeconds %}",
148-
"Output": "{% $states.input ~> |$|{}, ['Error', 'Cause']| %}",
149-
"Comment": "Deletes any past error",
148+
"Output": "{% $states.input ~> |$|{}, ['DbStatus', 'Error', 'Cause']| %}",
149+
"Comment": "Deletes possibly-stale status, and any past error",
150150
"Next": "IfEventNotExpiredChooseDbClusterOrInstance"
151151
},
152152
"Fail": {

step_stay_stopped_aws_rds_aurora.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ Resources:
835835
"Wait": {
836836
"Type": "Wait",
837837
"Seconds": "{% $Constant.StepFnWaitSeconds %}",
838-
"Output": "{% $states.input ~> |$|{}, ['Error', 'Cause']| %}",
839-
"Comment": "Deletes any past error",
838+
"Output": "{% $states.input ~> |$|{}, ['DbStatus', 'Error', 'Cause']| %}",
839+
"Comment": "Deletes possibly-stale status, and any past error",
840840
"Next": "IfEventNotExpiredChooseDbClusterOrInstance"
841841
},
842842
"Fail": {

0 commit comments

Comments
 (0)